Skip to content

Commit

Permalink
fix: wait for peer check
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-pousette committed Dec 5, 2023
1 parent fba99b6 commit a6a48e9
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions packages/transport/stream/src/__tests__/stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1320,15 +1320,16 @@ describe("join/leave", () => {
});

await waitForResolved(() =>
expect(streams[0].stream.peers.size).toEqual(2)
expect(
streams[0].stream.peers.has(streams[3].stream.publicKeyHash)
).toBeTrue()
);

expect(
streams[0].stream.peers.has(streams[3].stream.publicKeyHash)
).toBeTrue();
expect(
streams[3].stream.peers.has(streams[0].stream.publicKeyHash)
).toBeTrue();
await waitForResolved(() =>
expect(
streams[3].stream.peers.has(streams[0].stream.publicKeyHash)
).toBeTrue()
);

expect(streams[0].stream.peers.size).toEqual(2);
expect(streams[1].stream.peers.size).toEqual(2);
Expand Down Expand Up @@ -1472,7 +1473,7 @@ describe("join/leave", () => {
streams[0].stream.components.connectionManager.openConnection.bind(
streams[0].stream.components.connectionManager
);
let directlyDialded = false;
const filteredDial = (address: PeerId | Multiaddr | Multiaddr[]) => {
if (
Expand All @@ -1481,7 +1482,7 @@ describe("join/leave", () => {
) {
throw new Error("Mock fail"); // don't allow connect directly
}
let addresses: Multiaddr[] = Array.isArray(address)
? address
: [address as Multiaddr];
Expand All @@ -1498,11 +1499,11 @@ describe("join/leave", () => {
? multiaddr(x.toString().replace("/webrtc/", "/"))
: x
); // TODO use webrtc in node
directlyDialded = true;
return dialFn(addresses);
};
streams[0].stream.components.connectionManager.openConnection =
filteredDial;
expect(streams[0].stream.peers.size).toEqual(1);
Expand Down

0 comments on commit a6a48e9

Please sign in to comment.