Skip to content

Commit

Permalink
fix: improve container networking and test reliability - Update relay…
Browse files Browse the repository at this point in the history
… service to use container DNS names - Fix test node connectivity with proper container addressing - Add proper health checks for libp2p port

Co-Authored-By: Nico Krause <[email protected]>
  • Loading branch information
devin-ai-integration[bot] and silkroadnomad committed Dec 23, 2024
1 parent ce3289b commit 717a8b9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
13 changes: 8 additions & 5 deletions docker-compose-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ services:
volumes:
- ./docker/entrypoint.sh:/usr/src/app/entrypoint.sh
# - ./:/usr/src/app/
entrypoint: ["/usr/src/app/entrypoint.sh", "generate-key"]
entrypoint: ["/usr/src/app/entrypoint.sh", "start"]
healthcheck:
test: ["CMD", "nc", "-z", "localhost", "3000"]
test: ["CMD", "nc", "-z", "localhost", "9090"] # Check libp2p port instead
interval: 5s
timeout: 3s
retries: 3
depends_on:
- electrumx
- regtest
electrumx:
condition: service_healthy
regtest:
condition: service_started
ports:
- "1235:1235"
- "9090:9090" # Required for libp2p connectivity
Expand All @@ -53,8 +55,9 @@ services:
- "3000:3000"
environment:
- RELAY_LISTEN_ADDRESSES=/ip4/0.0.0.0/tcp/9090,/ip4/0.0.0.0/tcp/9091
- RELAY_ANNOUNCE_ADDRESSES=/ip4/127.0.0.1/tcp/9090,/ip4/127.0.0.1/tcp/9091
- RELAY_ANNOUNCE_ADDRESSES=/dns4/relay-service/tcp/9090,/dns4/relay-service/tcp/9091 # Use container DNS name
- RELAY_DEV_MODE=true # Enable dev mode for testing
- RELAY_PRIVATE_KEY=08011240053870142e367a49a603623d78ece265568ece425e195fb0540c27ed000bc2baf6f602d7717a7e26b07a8cff2c6784b3f7c9e36a01b5667e6894b6af41ed8b42 # Use consistent key

volumes:
doichain-data:
40 changes: 31 additions & 9 deletions relay/tests/relay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ const pubsubPeerDiscoveryTopics = process.env.RELAY_PUBSUB_PEER_DISCOVERY_TOPICS
const CONTENT_TOPIC = '/doichain-nfc/1/message/proto';

describe('Doichain Relay Pinning Service Test', function() {
this.timeout(100000);
this.timeout(300000); // Increase timeout for proper synchronization

let helia, fs, pubsub, db;
const messages = [];
const TIMEOUT = 5000;
const TIMEOUT = 30000; // Increase timeout for operations

// Helper function to check if OrbitDB has nameOps and relay connection is established
async function waitForNameOps(orbitdb, maxAttempts = 60) {
Expand All @@ -35,7 +35,7 @@ describe('Doichain Relay Pinning Service Test', function() {
console.log(`[waitForNameOps] Attempt ${attempt + 1}/${maxAttempts}`);

// Check relay connection first with retries
const targetPeerId = '12D3KooWQpeSaj6FR8SpnDzkESTXY5VqnZVWNUKrkqymGiZTZbW2';
const targetPeerId = '12D3KooWF5fGyE4VeXMhSGd9rCwckyxCVkA6xfoyFJG9DWJis62v'; // Match the configured private key
let isConnected = false;
let connectionAttempts = 0;
const maxConnectionAttempts = 3;
Expand All @@ -49,7 +49,7 @@ describe('Doichain Relay Pinning Service Test', function() {
console.log(`[waitForNameOps] Not connected to relay (attempt ${connectionAttempts}/${maxConnectionAttempts}), trying to connect...`);
try {
// Try to explicitly connect to the relay
const relayMa = `/ip4/127.0.0.1/tcp/9090/p2p/${targetPeerId}`;
const relayMa = `/dns4/relay-service/tcp/9090/p2p/${targetPeerId}`;
await helia.libp2p.dial(multiaddr(relayMa));
console.log('[waitForNameOps] Successfully dialed relay');
} catch (dialError) {
Expand Down Expand Up @@ -133,7 +133,29 @@ describe('Doichain Relay Pinning Service Test', function() {

// Wait for relay service to be ready
console.log('[Setup] Waiting for relay service to be ready...');
await new Promise((resolve) => setTimeout(resolve, 30000));
// Wait for relay service with exponential backoff
let waitTime = 5000;
const maxWaitTime = 60000;
let totalWaitTime = 0;

while (totalWaitTime < maxWaitTime) {
try {
const response = await fetch('http://relay-service:3000/api/v1/nameops/count');
if (response.ok) {
console.log('[Setup] Relay service is ready');
break;
}
} catch (error) {
console.log(`[Setup] Waiting for relay service (${totalWaitTime}ms / ${maxWaitTime}ms)`);
await new Promise((resolve) => setTimeout(resolve, waitTime));
totalWaitTime += waitTime;
waitTime = Math.min(waitTime * 2, 15000); // Cap at 15 seconds
}
}

if (totalWaitTime >= maxWaitTime) {
throw new Error('[Setup] Timeout waiting for relay service');
}

// Initialize Helia first
console.log('[Setup] Initializing Helia node...');
Expand All @@ -147,10 +169,10 @@ describe('Doichain Relay Pinning Service Test', function() {
identify: identify(),
},
addresses: {
listen: ['/ip4/127.0.0.1/tcp/4002', '/ip4/127.0.0.1/tcp/4003/ws']
listen: ['/ip4/0.0.0.0/tcp/4002', '/ip4/0.0.0.0/tcp/4003/ws']
},
peerDiscovery: [
bootstrap({ list: ['/ip4/127.0.0.1/tcp/9090/p2p/12D3KooWQpeSaj6FR8SpnDzkESTXY5VqnZVWNUKrkqymGiZTZbW2'] }),
bootstrap({ list: ['/dns4/relay-service/tcp/9090/p2p/12D3KooWF5fGyE4VeXMhSGd9rCwckyxCVkA6xfoyFJG9DWJis62v'] }), // Use container DNS name
pubsubPeerDiscovery({
interval: 10000,
topics: pubsubPeerDiscoveryTopics,
Expand Down Expand Up @@ -194,10 +216,10 @@ describe('Doichain Relay Pinning Service Test', function() {
identify: identify(),
},
addresses: {
listen: ['/ip4/127.0.0.1/tcp/4002', '/ip4/127.0.0.1/tcp/4003/ws']
listen: ['/ip4/0.0.0.0/tcp/4002', '/ip4/0.0.0.0/tcp/4003/ws']
},
peerDiscovery: [
bootstrap({ list: ['/ip4/127.0.0.1/tcp/9090/p2p/12D3KooWQpeSaj6FR8SpnDzkESTXY5VqnZVWNUKrkqymGiZTZbW2'] }),
bootstrap({ list: ['/dns4/relay-service/tcp/9090/p2p/12D3KooWF5fGyE4VeXMhSGd9rCwckyxCVkA6xfoyFJG9DWJis62v'] }), // Use container DNS name
pubsubPeerDiscovery({
interval: 10000,
topics: pubsubPeerDiscoveryTopics,
Expand Down

0 comments on commit 717a8b9

Please sign in to comment.