Skip to content

Commit 06a75e4

Browse files
committed
Retry loops in stress test
1 parent dcabf18 commit 06a75e4

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

tests/js/tests/neighbourhood.ts

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,12 @@ export default function neighbourhoodTests(testContext: TestContext) {
167167
}
168168
//await Promise.all(linkPromises)
169169

170-
console.log("wait 10s")
171-
await sleep(10000)
170+
console.log("wait 15s for initial sync")
171+
await sleep(15000)
172172

173173
let bobLinks = await bob.perspective.queryLinks(bobP1!.uuid, new LinkQuery({source: 'root'}))
174174
let tries = 1
175-
const maxTries = 120 // 2 minutes with 1 second sleep
175+
const maxTries = 180 // 3 minutes with 1 second sleep (increased for fallback sync)
176176

177177
while(bobLinks.length < 1500 && tries < maxTries) {
178178
console.log(`Bob retrying getting links... Got ${bobLinks.length}/1500`);
@@ -199,11 +199,19 @@ export default function neighbourhoodTests(testContext: TestContext) {
199199
await testContext.alice.perspective.addLink(aliceP1.uuid, {source: 'alice', target: 'test://alice/2'})
200200
await testContext.alice.perspective.addLink(aliceP1.uuid, {source: 'alice', target: 'test://alice/3'})
201201

202-
// Wait for sync
203-
await sleep(5000)
202+
// Wait for sync with retry loop
203+
bobLinks = await testContext.bob.perspective.queryLinks(bobP1.uuid, new LinkQuery({source: 'alice'}))
204+
let bobTries = 1
205+
const maxTriesBob = 20 // 20 tries with 2 second sleep = 40 seconds max
206+
207+
while(bobLinks.length < 3 && bobTries < maxTriesBob) {
208+
console.log(`Bob retrying getting Alice's links... Got ${bobLinks.length}/3`);
209+
await sleep(2000)
210+
bobLinks = await testContext.bob.perspective.queryLinks(bobP1.uuid, new LinkQuery({source: 'alice'}))
211+
bobTries++
212+
}
204213

205214
// Verify Bob received Alice's links
206-
bobLinks = await testContext.bob.perspective.queryLinks(bobP1.uuid, new LinkQuery({source: 'alice'}))
207215
expect(bobLinks.length).to.equal(3)
208216
expect(bobLinks.some(link => link.data.target === 'test://alice/1')).to.be.true
209217
expect(bobLinks.some(link => link.data.target === 'test://alice/2')).to.be.true
@@ -334,10 +342,21 @@ export default function neighbourhoodTests(testContext: TestContext) {
334342
})
335343

336344
it('they see each other in `otherAgents`', async () => {
337-
await sleep(10000);
338-
const aliceAgents = await aliceNH!.otherAgents()
345+
// Wait for agents to discover each other with retry loop
346+
let aliceAgents = await aliceNH!.otherAgents()
347+
let bobAgents = await bobNH!.otherAgents()
348+
let tries = 1
349+
const maxTries = 20 // 20 tries with 1 second sleep = 20 seconds max
350+
351+
while ((aliceAgents.length < 1 || bobAgents.length < 1) && tries < maxTries) {
352+
console.log(`Waiting for agents to discover each other... Alice: ${aliceAgents.length}, Bob: ${bobAgents.length}`);
353+
await sleep(1000)
354+
aliceAgents = await aliceNH!.otherAgents()
355+
bobAgents = await bobNH!.otherAgents()
356+
tries++
357+
}
358+
339359
console.log("alice agents", aliceAgents);
340-
const bobAgents = await bobNH!.otherAgents()
341360
console.log("bob agents", bobAgents);
342361
expect(aliceAgents.length).to.be.equal(1)
343362
expect(aliceAgents[0]).to.be.equal(bobDID)

0 commit comments

Comments
 (0)