Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replaced tests timeouts with flush helper #165

Merged
merged 6 commits into from
Dec 11, 2023
Merged

Conversation

rafapaezbas
Copy link
Contributor

This PR replaces the timeouts in tests that could be replaced by the flush helper. It does not replace back off timeouts because the logic for does tests do not allow the replacement.

@rafapaezbas rafapaezbas force-pushed the replace-test-timeouts branch from fdbb998 to d76918c Compare December 7, 2023 12:31
test/swarm.js Outdated Show resolved Hide resolved
test/swarm.js Outdated Show resolved Hide resolved
test/swarm.js Outdated Show resolved Hide resolved
@mafintosh
Copy link
Contributor

CI is failing

@HDegroote
Copy link
Contributor

Yeah, I think we got lucky and discovered another flaky test relying on TIMEOUTS (it's not a test which was modified in this PR)

hyperswarm/test/swarm.js

Lines 360 to 402 in 2229393

test('one server, one client - correct deduplication when a client connection is destroyed', async (t) => {
const { bootstrap } = await createTestnet(3, t.teardown)
const swarm1 = new Hyperswarm({ bootstrap, backoffs: BACKOFFS, jitter: 0 })
const swarm2 = new Hyperswarm({ bootstrap, backoffs: BACKOFFS, jitter: 0 })
let clientConnections = 0
let serverConnections = 0
let clientData = 0
let serverData = 0
const RECONNECT_TIMEOUT = CONNECTION_TIMEOUT * 4
swarm1.on('connection', (conn) => {
serverConnections++
conn.on('error', noop)
conn.on('data', () => serverData++)
conn.write('hello world')
})
swarm2.on('connection', (conn) => {
clientConnections++
conn.on('error', noop)
conn.on('data', () => clientData++)
conn.write('hello world')
if (clientConnections === 1) setTimeout(() => conn.destroy(), 100) // Destroy the first client connection
})
const topic = Buffer.alloc(32).fill('hello world')
await swarm1.join(topic, { server: true, client: false }).flushed()
swarm2.join(topic, { server: false, client: true })
await swarm2.flush()
await timeout(RECONNECT_TIMEOUT) // Wait for the first connection to be destroyed/reestablished.
t.is(clientConnections, 2)
t.is(serverConnections, 2)
t.is(clientData, 2)
t.is(serverData, 2)
await swarm1.destroy()
await swarm2.destroy()
})

Copy link
Contributor

@HDegroote HDegroote left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. The flaky test discussed above needs to be fixed though, but can be in another PR

Edit: managed to reproduce the flakiness: https://github.com/holepunchto/hyperswarm/actions/runs/7170541056/job/19523507101 . It's pretty rare, 80 repetitions before it hit. Probably fixable by using the flush helper of this PR--will look into that once this is merged

@mafintosh mafintosh merged commit 8356bfd into main Dec 11, 2023
4 checks passed
@mafintosh mafintosh deleted the replace-test-timeouts branch December 11, 2023 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants