Skip to content

Commit 3bcf9ff

Browse files
committed
Tests..ongoing
1 parent b77268b commit 3bcf9ff

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

packages/bolt-connection/test/channel/browser/browser-channel.test.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,67 @@ describe('WebSocketChannel', () => {
360360
})
361361
})
362362

363+
describe('.startReceiveTimeout()', () => {
364+
let fakeSetTimeout
365+
beforeEach(() => {
366+
const address = ServerAddress.fromUrl('http://localhost:8989')
367+
const channelConfig = new ChannelConfig(
368+
address,
369+
{ connectionTimeout: 0 },
370+
SERVICE_UNAVAILABLE
371+
)
372+
webSocketChannel = new WebSocketChannel(
373+
channelConfig,
374+
undefined,
375+
createWebSocketFactory(WS_OPEN)
376+
)
377+
fakeSetTimeout = setTimeoutMock.install()
378+
fakeSetTimeout.pause()
379+
})
380+
381+
afterEach(() => {
382+
fakeSetTimeout.uninstall()
383+
})
384+
385+
describe('receive timeout is setup', () => {
386+
const receiveTimeout = 1000
387+
beforeEach(() => {
388+
webSocketChannel.setupReceiveTimeout(receiveTimeout)
389+
})
390+
391+
it('should call setTimeout(receiveTimeout) when it call first', () => {
392+
webSocketChannel.startReceiveTimeout()
393+
394+
expect(fakeSetTimeout._timeoutIdCounter).toEqual(1)
395+
expect(fakeSetTimeout.invocationDelays).toEqual([receiveTimeout])
396+
expect(fakeSetTimeout.clearedTimeouts).toEqual([])
397+
})
398+
399+
it('should call not setTimeout(receiveTimeout) when already started', () => {
400+
webSocketChannel.startReceiveTimeout()
401+
402+
expect(fakeSetTimeout._timeoutIdCounter).toEqual(1)
403+
expect(fakeSetTimeout.invocationDelays).toEqual([receiveTimeout])
404+
expect(fakeSetTimeout.clearedTimeouts).toEqual([])
405+
406+
// webSocketChannel.startReceiveTimeout()
407+
408+
// expect(fakeSetTimeout._timeoutIdCounter).toEqual(1)
409+
// expect(fakeSetTimeout.invocationDelays).toEqual([receiveTimeout])
410+
// expect(fakeSetTimeout.clearedTimeouts).toEqual([])
411+
})
412+
})
413+
414+
describe('receive timeout is not setup', () => {
415+
it('should not call setTimeout(receiveTimeout) when not configured', () => {
416+
// start
417+
webSocketChannel.startReceiveTimeout()
418+
419+
expect(fakeSetTimeout._timeoutIdCounter).toEqual(0)
420+
})
421+
})
422+
})
423+
363424
function createWebSocketFactory (readyState) {
364425
const ws = {}
365426
ws.readyState = readyState

packages/bolt-connection/test/timers-util.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class SetTimeoutMock {
2828
code()
2929
this.invocationDelays.push(delay)
3030
}
31+
this.calls.push([...arguments])
3132
return this._timeoutIdCounter++
3233
}
3334

@@ -59,6 +60,7 @@ class SetTimeoutMock {
5960
this._paused = false
6061
this._timeoutIdCounter = 0
6162

63+
this.calls = []
6264
this.invocationDelays = []
6365
this.clearedTimeouts = []
6466
}

0 commit comments

Comments
 (0)