Skip to content

Commit

Permalink
Make createPlayer have a small delay (#98)
Browse files Browse the repository at this point in the history
Give the Network a little bit of time to connect to the signalling
backend before we continue with the next step. This makes our tests less
flaky. Found out when some lobby tests where we create multiple players
after each other was failing because their ID was changing (as they are
given out in order).
  • Loading branch information
erikdubbelboer authored Jun 18, 2024
1 parent 3f7c2f7 commit 0c99ee9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
6 changes: 3 additions & 3 deletions features/support/steps/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ After(async function (this: World) {
})

Given('{string} is connected and ready for game {string}', async function (this: World, playerName: string, gameID: string) {
const player = this.createPlayer(playerName, gameID)
const player = await this.createPlayer(playerName, gameID)
const event = await player.waitForEvent('ready')
if (event == null) {
throw new Error(`unable to add player ${playerName} to network`)
Expand Down Expand Up @@ -96,8 +96,8 @@ Given('these lobbies exist:', async function (this: World, lobbies: DataTable) {
})
})

When('{string} creates a network for game {string}', function (this: World, playerName: string, gameID: string) {
this.createPlayer(playerName, gameID)
When('{string} creates a network for game {string}', async function (this: World, playerName: string, gameID: string) {
await this.createPlayer(playerName, gameID)
})

When('{string} creates a lobby', function (this: World, playerName: string) {
Expand Down
19 changes: 13 additions & 6 deletions features/support/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,19 @@ export class World extends CucumberWorld {
}
}

public createPlayer (playerName: string, gameID: string): Player {
const config = this.useTestProxy ? { testproxyURL: this.testproxyURL } : undefined
const network = new Network(gameID, config, this.signalingURL)
const player = new Player(playerName, network)
this.players.set(playerName, player)
return player
public async createPlayer (playerName: string, gameID: string): Promise<Player> {
return await new Promise((resolve) => {
const config = this.useTestProxy ? { testproxyURL: this.testproxyURL } : undefined
const network = new Network(gameID, config, this.signalingURL)
const player = new Player(playerName, network)
this.players.set(playerName, player)

// Give the Network some time to connect to the signaling server.
// Giving this some time makes our test less flaky.
setTimeout(() => {
resolve(player)
}, 50)
})
}
}
setWorldConstructor(World)
Expand Down

0 comments on commit 0c99ee9

Please sign in to comment.