Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
ibc committed Jan 5, 2024
1 parent c8b9a1c commit 7ce691f
Showing 1 changed file with 141 additions and 0 deletions.
141 changes: 141 additions & 0 deletions node/src/test/test-Consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,144 @@ test('Consumer emits "score"', async () =>
{ score: 9, producerScore: 10, producerScores: [ 8 ] });
log('>>> score test 10');
}, 2000);

test('consumer.close() succeeds', async () =>
{
const audioConsumer = await ctx.transport2!.consume(
{
producerId : ctx.audioProducer!.id,
rtpCapabilities : ctx.consumerDeviceCapabilities
});
const videoConsumer = await ctx.transport2!.consume(
{
producerId : ctx.videoProducer!.id,
rtpCapabilities : ctx.consumerDeviceCapabilities
});
const onObserverClose = jest.fn();

audioConsumer.observer.once('close', onObserverClose);
audioConsumer.close();

expect(onObserverClose).toHaveBeenCalledTimes(1);
expect(audioConsumer.closed).toBe(true);

const routerDump = await ctx.router!.dump();

expect(routerDump.mapProducerIdConsumerIds)
.toEqual(expect.arrayContaining(
[
{ key: ctx.audioProducer!.id, values: [] },
{ key: ctx.videoProducer!.id, values: [ videoConsumer.id ] }
]));
expect(routerDump.mapConsumerIdProducerId)
.toEqual(
[
{ key: videoConsumer!.id, value: ctx.videoProducer!.id }
]);

const transportDump = await ctx.transport2!.dump();

expect(transportDump)
.toMatchObject(
{
id : ctx.transport2!.id,
producerIds : [],
consumerIds : [ videoConsumer.id ]
});
}, 2000);

test('Consumer methods reject if closed', async () =>
{
const audioConsumer = await ctx.transport2!.consume(
{
producerId : ctx.audioProducer!.id,
rtpCapabilities : ctx.consumerDeviceCapabilities
});

audioConsumer.close();

await expect(audioConsumer.dump())
.rejects
.toThrow(Error);

await expect(audioConsumer.getStats())
.rejects
.toThrow(Error);

await expect(audioConsumer.pause())
.rejects
.toThrow(Error);

await expect(audioConsumer.resume())
.rejects
.toThrow(Error);

// @ts-ignore
await expect(audioConsumer.setPreferredLayers({}))
.rejects
.toThrow(Error);

await expect(audioConsumer.setPriority(2))
.rejects
.toThrow(Error);

await expect(audioConsumer.requestKeyFrame())
.rejects
.toThrow(Error);
}, 2000);

test('Consumer emits "producerclose" if Producer is closed', async () =>
{
const audioConsumer = await ctx.transport2!.consume(
{
producerId : ctx.audioProducer!.id,
rtpCapabilities : ctx.consumerDeviceCapabilities
});
const onObserverClose = jest.fn();

audioConsumer.observer.once('close', onObserverClose);

await new Promise<void>((resolve) =>
{
audioConsumer.on('producerclose', resolve);
ctx.audioProducer!.close();
});

expect(onObserverClose).toHaveBeenCalledTimes(1);
expect(audioConsumer.closed).toBe(true);
}, 2000);

test('Consumer emits "transportclose" if Transport is closed', async () =>
{
const videoConsumer = await ctx.transport2!.consume(
{
producerId : ctx.videoProducer!.id,
rtpCapabilities : ctx.consumerDeviceCapabilities
});

const onObserverClose = jest.fn();

videoConsumer.observer.once('close', onObserverClose);

await new Promise<void>((resolve) =>
{
videoConsumer.on('transportclose', resolve);
ctx.transport2!.close();
});

expect(onObserverClose).toHaveBeenCalledTimes(1);
expect(videoConsumer.closed).toBe(true);

await expect(ctx.router!.dump())
.resolves
.toMatchObject(
{
mapProducerIdConsumerIds : expect.arrayContaining(
[
{ key: ctx.audioProducer!.id, values: [] },
{ key: ctx.videoProducer!.id, values: [] }
]
),
mapConsumerIdProducerId : []
});
}, 2000);

0 comments on commit 7ce691f

Please sign in to comment.