Skip to content

Commit

Permalink
WIP: Serious test of echo ordering test case
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Dec 13, 2023
1 parent 5757126 commit a5944e9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 33 deletions.
1 change: 1 addition & 0 deletions src/handling/handler-steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export class EchoStep extends EchoStepDefinition {

async handle(connection: MockRTCConnection): Promise<void> {
const echoContent = (stream: DataChannelStream | MediaTrackStream) => {
stream.on('data', (d) => console.log('MockRTC echoing', d));
stream.pipe(stream);
};

Expand Down
74 changes: 41 additions & 33 deletions test/integration/echo-steps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,49 @@ describe("Echo steps", function () {
beforeEach(() => mockRTC.start());
afterEach(() => mockRTC.stop());

it("should be able to echo messages across multiple data channels", async () => {
const mockPeer = await mockRTC.buildPeer()
.thenEcho();

const localConnection = new RTCPeerConnection();
const dataChannel1 = localConnection.createDataChannel("dataChannel1");

const localOffer = await localConnection.createOffer();
await localConnection.setLocalDescription(localOffer);
const { answer } = await mockPeer.answerOffer(localOffer);
await localConnection.setRemoteDescription(answer);

let messages: Array<any> = [];
dataChannel1.addEventListener('message', (event) => messages.push("1: " + event.data));

await waitForChannelOpen(dataChannel1);
dataChannel1.send('Test message 1');

const dataChannel2 = localConnection.createDataChannel("dataChannel2");
dataChannel2.addEventListener('message', (event) => messages.push("2: " + event.data));
await waitForChannelOpen(dataChannel2);
await delay(50); // Delay to guarantee ordering
dataChannel2.send('Test message 2');

await delay(50); // Delay to guarantee ordering
dataChannel1.send('Test message 3');
for (let i = 0; i < 1000; i++) {
it.only(`${i} should be able to echo messages across multiple data channels`, async () => {
const mockPeer = await mockRTC.buildPeer()
.thenEcho();

const localConnection = new RTCPeerConnection();
const dataChannel1 = localConnection.createDataChannel("dataChannel1");
console.log('DC1 is ordered?', dataChannel1.ordered);

const localOffer = await localConnection.createOffer();
await localConnection.setLocalDescription(localOffer);
const { answer } = await mockPeer.answerOffer(localOffer);
await localConnection.setRemoteDescription(answer);

let messages: Array<any> = [];
dataChannel1.addEventListener('message', (event) => {
console.log('Client got message on DC1', event.data);
messages.push("1: " + event.data);
});

await delay(50); // Delay to guarantee delivery
await waitForChannelOpen(dataChannel1);
dataChannel1.send('Test message 1');

expect(messages).to.deep.equal([
'1: Test message 1',
'2: Test message 2',
'1: Test message 3',
]);
});
const dataChannel2 = localConnection.createDataChannel("dataChannel2");
console.log('DC2 is ordered?', dataChannel2.ordered);
dataChannel2.addEventListener('message', (event) => {
console.log('Client got message on DC2', event.data);
messages.push("2: " + event.data)
});
await waitForChannelOpen(dataChannel2);
dataChannel1.send('Test message 2');
await delay(1);
dataChannel2.send('Test message 3');

await delay(100); // Delay to guarantee delivery

expect(messages).to.deep.equal([
'1: Test message 1',
'1: Test message 2',
'2: Test message 3',
]);
});
}

it("should be able to echo media", async () => {
const mockPeer = await mockRTC.buildPeer()
Expand Down

0 comments on commit a5944e9

Please sign in to comment.