-
Notifications
You must be signed in to change notification settings - Fork 11
/
core-013-non-get-timeout.js
56 lines (43 loc) · 1.62 KB
/
core-013-non-get-timeout.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
Handle an exchange timeout for a non-confirmable GET request:
1. Client sends a request:
==============================================================================
Version | Type | Token Length | Code | Message ID
0 1 | 0 1 | 0 0 0 0 | 0 0 0 0 0 0 0 1 | 0x0001
1 | NON | 0 bytes | GET | 1
------------------------------------------------------------------------------
Remote Endpoint: 127.0.0.1
------------------------------------------------------------------------------
Uri-Path: temperature
==============================================================================
2. The #1 request is lost along the way...
3. ...client waits 64s and emits the `exchange timeout` event and the request
emits the `timeout` event.
*/
'use strict';
require('should');
var sinon = require('sinon');
var helpers = require('../helpers');
var Message = require(helpers.LIB_DIR).Message;
helpers.test(__filename, function(ctx)
{
var expectedRequest = {
type: Message.Type.NON,
code: Message.Code.GET,
id: 0x0001,
uri: '/temperature'
};
ctx.socket.expectRequest(expectedRequest);
var clientEventSpy = sinon.spy(ctx.client, 'emit');
var req = ctx.client.request(Message.fromObject(expectedRequest));
var eventSpy = sinon.spy(req, 'emit');
ctx.clock.tick(3600000);
return function assert()
{
ctx.socket.assert();
sinon.assert.calledWithExactly(clientEventSpy, 'exchange timeout', req);
sinon.assert.calledAt(clientEventSpy, ctx.startTime + 64000);
sinon.assert.callCount(eventSpy, 1);
sinon.assert.calledWith(eventSpy, 'timeout');
};
});