-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream-management: fix enabling when the next element is not the resp…
…onse (#823)
- Loading branch information
Showing
4 changed files
with
185 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,169 @@ | ||
'use strict' | ||
|
||
const test = require('ava') | ||
const {mockClient, promise, timeout} = require('@xmpp/test') | ||
const {mockClient} = require('@xmpp/test') | ||
|
||
test('mandatory', async t => { | ||
function tick() { | ||
return new Promise(resolve => process.nextTick(resolve)) | ||
} | ||
|
||
test('enable - enabled', async t => { | ||
const {entity} = mockClient() | ||
|
||
entity.mockInput( | ||
<features xmlns="http://etherx.jabber.org/streams"> | ||
<session xmlns="urn:ietf:params:xml:ns:xmpp-session" /> | ||
<sm xmlns="urn:xmpp:sm:3" /> | ||
</features> | ||
) | ||
|
||
entity.scheduleIncomingResult() | ||
entity.streamManagement.outbound = 45 | ||
|
||
t.deepEqual( | ||
await entity.catchOutgoing(), | ||
<enable xmlns="urn:xmpp:sm:3" resume="true" /> | ||
) | ||
|
||
t.is(entity.streamManagement.outbound, 0) | ||
t.is(entity.streamManagement.enabled, false) | ||
t.is(entity.streamManagement.id, '') | ||
|
||
await entity.catchOutgoingSet().then(child => { | ||
t.deepEqual(child, <session xmlns="urn:ietf:params:xml:ns:xmpp-session" />) | ||
return child | ||
}) | ||
entity.mockInput( | ||
<enabled | ||
xmlns="urn:xmpp:sm:3" | ||
id="some-long-sm-id" | ||
location="[2001:41D0:1:A49b::1]:9222" | ||
resume="true" | ||
/> | ||
) | ||
|
||
await promise(entity, 'online') | ||
await tick() | ||
|
||
t.is(entity.streamManagement.id, 'some-long-sm-id') | ||
t.is(entity.streamManagement.enabled, true) | ||
}) | ||
|
||
test('optional', async t => { | ||
test('enable - message - enabled', async t => { | ||
const {entity} = mockClient() | ||
|
||
entity.mockInput( | ||
<features xmlns="http://etherx.jabber.org/streams"> | ||
<session xmlns="urn:ietf:params:xml:ns:xmpp-session"> | ||
<optional /> | ||
</session> | ||
<sm xmlns="urn:xmpp:sm:3" /> | ||
</features> | ||
) | ||
|
||
const promiseSend = promise(entity, 'send') | ||
entity.streamManagement.outbound = 45 | ||
|
||
t.deepEqual( | ||
await entity.catchOutgoing(), | ||
<enable xmlns="urn:xmpp:sm:3" resume="true" /> | ||
) | ||
|
||
t.is(entity.streamManagement.outbound, 0) | ||
t.is(entity.streamManagement.enabled, false) | ||
t.is(entity.streamManagement.id, '') | ||
|
||
entity.mockInput(<message />) | ||
|
||
t.is(entity.streamManagement.enabled, false) | ||
t.is(entity.streamManagement.inbound, 1) | ||
|
||
entity.mockInput( | ||
<enabled | ||
xmlns="urn:xmpp:sm:3" | ||
id="some-long-sm-id" | ||
location="[2001:41D0:1:A49b::1]:9222" | ||
resume="true" | ||
/> | ||
) | ||
|
||
await tick() | ||
|
||
t.is(entity.streamManagement.id, 'some-long-sm-id') | ||
t.is(entity.streamManagement.enabled, true) | ||
}) | ||
|
||
test('enable - failed', async t => { | ||
const {entity} = mockClient() | ||
|
||
entity.mockInput( | ||
<features xmlns="http://etherx.jabber.org/streams"> | ||
<sm xmlns="urn:xmpp:sm:3" /> | ||
</features> | ||
) | ||
|
||
entity.streamManagement.outbound = 45 | ||
|
||
t.deepEqual( | ||
await entity.catchOutgoing(), | ||
<enable xmlns="urn:xmpp:sm:3" resume="true" /> | ||
) | ||
|
||
t.is(entity.streamManagement.outbound, 0) | ||
entity.streamManagement.enabled = true | ||
|
||
entity.mockInput(<failed xmlns="urn:xmpp:sm:3" />) | ||
|
||
await tick() | ||
|
||
t.is(entity.streamManagement.enabled, false) | ||
}) | ||
|
||
test('resume - resumed', async t => { | ||
const {entity} = mockClient() | ||
|
||
entity.status = 'offline' | ||
entity.streamManagement.id = 'bar' | ||
|
||
entity.mockInput( | ||
<features xmlns="http://etherx.jabber.org/streams"> | ||
<sm xmlns="urn:xmpp:sm:3" /> | ||
</features> | ||
) | ||
|
||
entity.streamManagement.outbound = 45 | ||
|
||
t.deepEqual( | ||
await entity.catchOutgoing(), | ||
<resume xmlns="urn:xmpp:sm:3" previd="bar" h="0" /> | ||
) | ||
|
||
t.is(entity.streamManagement.enabled, false) | ||
|
||
t.is(entity.status, 'offline') | ||
|
||
entity.mockInput(<resumed xmlns="urn:xmpp:sm:3" />) | ||
|
||
await tick() | ||
|
||
t.is(entity.streamManagement.outbound, 45) | ||
t.is(entity.status, 'online') | ||
}) | ||
|
||
test('resume - failed', async t => { | ||
const {entity} = mockClient() | ||
|
||
entity.status = 'bar' | ||
entity.streamManagement.id = 'bar' | ||
entity.streamManagement.enabled = true | ||
entity.streamManagement.outbound = 45 | ||
|
||
entity.mockInput( | ||
<features xmlns="http://etherx.jabber.org/streams"> | ||
<sm xmlns="urn:xmpp:sm:3" /> | ||
</features> | ||
) | ||
|
||
t.deepEqual( | ||
await entity.catchOutgoing(), | ||
<resume xmlns="urn:xmpp:sm:3" previd="bar" h="0" /> | ||
) | ||
|
||
entity.mockInput(<failed xmlns="urn:xmpp:sm:3" />) | ||
|
||
await promise(entity, 'online') | ||
await tick() | ||
|
||
await timeout(promiseSend, 0).catch(err => { | ||
t.is(err.name, 'TimeoutError') | ||
}) | ||
t.is(entity.status, 'bar') | ||
t.is(entity.streamManagement.id, '') | ||
t.is(entity.streamManagement.enabled, false) | ||
t.is(entity.streamManagement.outbound, 0) | ||
}) |