@rootintf/protocol-2phw 2.2.2-api.2 → 2.3.7-api.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/twoPhW.cjs.js +8 -114
- package/dist/twoPhW.d.ts +2 -2
- package/dist/twoPhW.es.mjs +9 -114
- package/package.json +9 -2
- package/src/twoPhW.ts +6 -7
- package/dev.txt +0 -23
- package/dist/EventLog-mem.d.mts +0 -28
- package/jasmine.json +0 -7
- package/rollup.config.mjs +0 -35
- package/src/EventLog-mem.mjs +0 -133
- package/tests/event-log-mem.spec.mjs +0 -239
- package/tests/twoPhW-new.spec.mjs +0 -850
- package/tsconfig.json +0 -115
|
@@ -1,850 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
-
import { LOGR, l_concat } from '@knev/bitlogr';
|
|
4
|
-
import {
|
|
5
|
-
StateAckEngage, StateEngage, StateAckWarp, StateWarp, StateInitialState, StateINVALID,
|
|
6
|
-
EventLog,
|
|
7
|
-
t_ttl_rtt,
|
|
8
|
-
TwoPhW, JSON_MsgOptions, JSON_MsgWarp, JSON_MsgEngage, JSON_MsgAckWarp, JSON_MsgAckEngage,
|
|
9
|
-
logr as logr_,
|
|
10
|
-
JSON_Msg, JSON_MsgEffect, JSON_MsgAck
|
|
11
|
-
} from '../dist/twoPhW.es.mjs';
|
|
12
|
-
|
|
13
|
-
// this leads to two copies of l_ from '@rootintf/json-msg'; one copy from twoPhW
|
|
14
|
-
// import { JSON_Msg, JSON_MsgEffect, JSON_MsgAck, l as l_json_msg } from '@rootintf/json-msg'
|
|
15
|
-
|
|
16
|
-
const k_VERSION= "2";
|
|
17
|
-
|
|
18
|
-
const kstr_REFERER_ = 'twoPhW-new.spec';
|
|
19
|
-
const karr_referer_src = [kstr_REFERER_, uuidv4()];
|
|
20
|
-
const karr_referer_dst = [kstr_REFERER_, uuidv4()];
|
|
21
|
-
|
|
22
|
-
const T0= 1000000; // Fixed base time: 1,000,000 ms
|
|
23
|
-
const TTL_MSEC_1500= 1500;
|
|
24
|
-
const STT_MSEC_1000= 1000; // SINGLE trip time = half the RTT
|
|
25
|
-
const RTT_MSEC_2000= 2000;
|
|
26
|
-
|
|
27
|
-
//-------------------------------------------------------------------------------------------------
|
|
28
|
-
|
|
29
|
-
const LOGR_= LOGR.get_instance();
|
|
30
|
-
const l_= logr_.l;
|
|
31
|
-
|
|
32
|
-
LOGR_.toggle(l_, {
|
|
33
|
-
VALIDATION : true
|
|
34
|
-
});
|
|
35
|
-
logr_.raw('twoPhW-new.spec: const l_ ', l_.get())
|
|
36
|
-
|
|
37
|
-
//-------------------------------------------------------------------------------------------------
|
|
38
|
-
|
|
39
|
-
describe("Initialization", function () {
|
|
40
|
-
it("json_msgWarp", function () {
|
|
41
|
-
const json_msgWarp= JSON_MsgWarp.create_with_id_user_hyperport(uuidv4(), '', '', TTL_MSEC_1500);
|
|
42
|
-
|
|
43
|
-
const json_msgAckWarp_obj= JSON_MsgAckWarp.create_with_Warp_Ok(json_msgWarp, true);
|
|
44
|
-
const json_msgAckWarp_str= JSON_MsgAckWarp.create_with_Warp_Ok( JSON.stringify(json_msgWarp), true);
|
|
45
|
-
|
|
46
|
-
expect(typeof json_msgAckWarp_obj._cause.warp.id === 'string').toBe(true);
|
|
47
|
-
expect(() => {
|
|
48
|
-
json_msgAckWarp_str._cause.warp.id;
|
|
49
|
-
}).toThrowError(TypeError, "Cannot read properties of undefined (reading 'id')");
|
|
50
|
-
|
|
51
|
-
expect(() => {
|
|
52
|
-
const isInstance = json_msgWarp instanceof JSON_Msg; // This will throw
|
|
53
|
-
}).toThrowError(TypeError, /Right-hand side of 'instanceof' is not callable/);
|
|
54
|
-
|
|
55
|
-
expect(json_msgWarp.warp !== undefined).toBe(true);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
//-------------------------------------------------------------------------------------------------
|
|
60
|
-
|
|
61
|
-
describe("Validation", function () {
|
|
62
|
-
|
|
63
|
-
const json_msgWarp_ = {
|
|
64
|
-
id: "f5d6c2b8-1481-49b2-882c-262bb1c9ef8c",
|
|
65
|
-
referer: ["twoPhW", "af9447e3-4b36-424f-8d07-976a9216a298"],
|
|
66
|
-
dt: "2022-10-28T06:26:19.692Z",
|
|
67
|
-
warp: {
|
|
68
|
-
id: "f5d6c2b8-1481-49b2-882c-262bb1c9ef8c",
|
|
69
|
-
user: {},
|
|
70
|
-
hyperport: {},
|
|
71
|
-
ttl_msec : 3000
|
|
72
|
-
},
|
|
73
|
-
"2PhW": k_VERSION
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const json_msgEngage_ = {
|
|
77
|
-
id: "f5d6c2b8-1481-49b2-882c-262bb1c9ef8c",
|
|
78
|
-
referer: ["twoPhW", "af9447e3-4b36-424f-8d07-976a9216a298"],
|
|
79
|
-
dt: "2022-10-28T06:26:19.692Z",
|
|
80
|
-
engage: {
|
|
81
|
-
"ok" : true,
|
|
82
|
-
"rtt_msec" : 6000
|
|
83
|
-
},
|
|
84
|
-
"_cause" : json_msgWarp_,
|
|
85
|
-
"2PhW": k_VERSION
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const json_msgAckWarp_str_ = {
|
|
89
|
-
id: "f5d6c2b8-1481-49b2-882c-262bb1c9ef8c",
|
|
90
|
-
referer: ["twoPhW", "af9447e3-4b36-424f-8d07-976a9216a298"],
|
|
91
|
-
dt: "2022-10-28T06:26:19.692Z",
|
|
92
|
-
ack: {
|
|
93
|
-
"ok" : true,
|
|
94
|
-
},
|
|
95
|
-
"_cause" : JSON.stringify( json_msgWarp_ ),
|
|
96
|
-
"2PhW": k_VERSION
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const json_msgAckWarp_obj_ = {
|
|
100
|
-
id: "f5d6c2b8-1481-49b2-882c-262bb1c9ef8c",
|
|
101
|
-
referer: ["twoPhW", "af9447e3-4b36-424f-8d07-976a9216a298"],
|
|
102
|
-
dt: "2022-10-28T06:26:19.692Z",
|
|
103
|
-
ack: {
|
|
104
|
-
"ok" : true,
|
|
105
|
-
},
|
|
106
|
-
"_cause" : json_msgWarp_,
|
|
107
|
-
"2PhW": k_VERSION
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const json_msgAckEngage_ = {
|
|
111
|
-
id: "f5d6c2b8-1481-49b2-882c-262bb1c9ef8c",
|
|
112
|
-
referer: ["twoPhW", "af9447e3-4b36-424f-8d07-976a9216a298"],
|
|
113
|
-
dt: "2022-10-28T06:26:19.692Z",
|
|
114
|
-
ack: {
|
|
115
|
-
"ok" : false,
|
|
116
|
-
},
|
|
117
|
-
"_cause" : json_msgEngage_,
|
|
118
|
-
"2PhW": k_VERSION
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
//TODO: "required" : ["reason"],
|
|
122
|
-
const json_msgOptions_ = {
|
|
123
|
-
id: "f5d6c2b8-1481-49b2-882c-262bb1c9ef8c",
|
|
124
|
-
referer: ["twoPhW", "af9447e3-4b36-424f-8d07-976a9216a298"],
|
|
125
|
-
dt: "2022-10-28T06:26:19.692Z",
|
|
126
|
-
options: {
|
|
127
|
-
ttl_msec_incr : [ 20000, 4000 ],
|
|
128
|
-
reason : "it is taking too long"
|
|
129
|
-
},
|
|
130
|
-
"_cause" : json_msgWarp_,
|
|
131
|
-
"2PhW": k_VERSION
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
it("JSON_Msg.validate(json_msgWarp_)", function () {
|
|
135
|
-
expect( JSON_Msg.validate(json_msgWarp_) ).toBe(true);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it("twoPhW.JSON_MsgOptions.validate(json_msgOptions_)", function () {
|
|
139
|
-
expect( JSON_MsgOptions.validate(json_msgOptions_) ).toBe(true);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("twoPhW.JSON_MsgWarp.validate(json_msgWarp_)", function () {
|
|
143
|
-
expect( JSON_MsgWarp.validate(json_msgWarp_) ).toBe(true);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it("twoPhW.JSON_MsgEngage.validate(json_msgEngage_)", function () {
|
|
147
|
-
expect( JSON_MsgEngage.validate(json_msgEngage_) ).toBe(true);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it("JSON_MsgAckWarp.validate(json_msgAckWarp_str_)", function () {
|
|
151
|
-
expect( JSON_MsgAckWarp.validate(json_msgAckWarp_str_) ).toBe(false);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it("JSON_MsgAckWarp.validate(json_msgAckWarp_obj_)", function () {
|
|
155
|
-
expect( JSON_MsgAckWarp.validate(json_msgAckWarp_obj_) ).toBe(true);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it("JSON_MsgAckEngage.validate(json_msgAckEngage_)", function () {
|
|
159
|
-
expect( JSON_MsgAckEngage.validate(json_msgAckEngage_) ).toBe(true);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it("LOGR test", function () {
|
|
163
|
-
const json_msgWarp= JSON_MsgWarp.create_with_id_user_hyperport(
|
|
164
|
-
"f5d6c2b8-1481-49b2-882c-262bb1c9ef8c",
|
|
165
|
-
'',
|
|
166
|
-
'',
|
|
167
|
-
3000
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
LOGR_.toggle(l_, {
|
|
171
|
-
VALIDATION : true
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
expect( JSON_MsgEffect.validate(json_msgWarp) ).toBe(false);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
//-------------------------------------------------------------------------------------------------
|
|
180
|
-
|
|
181
|
-
describe('2PhW protocol', () => {
|
|
182
|
-
let eventLog;
|
|
183
|
-
let twoPhW;
|
|
184
|
-
|
|
185
|
-
beforeEach(() => {
|
|
186
|
-
eventLog = new EventLog();
|
|
187
|
-
twoPhW= new TwoPhW(eventLog);
|
|
188
|
-
|
|
189
|
-
// spyOn(eventLog.logr, 'log'); // Mock logging
|
|
190
|
-
jasmine.clock().install();
|
|
191
|
-
jasmine.clock().mockDate(new Date(T0));
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
afterEach(() => {
|
|
195
|
-
jasmine.clock().uninstall();
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
describe('basics', () => {
|
|
199
|
-
it('addEvent', () => {
|
|
200
|
-
const json_msgWarp= JSON_MsgWarp.create_with_id_user_hyperport(uuidv4(), '', '', TTL_MSEC_1500);
|
|
201
|
-
json_msgWarp.referer= karr_referer_src;
|
|
202
|
-
|
|
203
|
-
const json_msgEngage= JSON_MsgEngage.create_with_Warp(json_msgWarp);
|
|
204
|
-
json_msgEngage.referer= karr_referer_src;
|
|
205
|
-
|
|
206
|
-
const json_msgNackWarp= JSON_MsgAckWarp.create_with_Warp_Ok(json_msgWarp, false);
|
|
207
|
-
json_msgNackWarp.referer= karr_referer_dst;
|
|
208
|
-
const str_msgNackWarp = JSON.stringify(json_msgNackWarp);
|
|
209
|
-
twoPhW.eventLog._addEvent(str_msgNackWarp, json_msgNackWarp)
|
|
210
|
-
expect(eventLog.arr_events.length).toBe(1);
|
|
211
|
-
expect(eventLog.arr_events[0].type).toBe('2PhW[JSON_MsgAckWarp]');
|
|
212
|
-
expect(eventLog.arr_events[0].data).toEqual({ msg: str_msgNackWarp, json_msg : json_msgNackWarp });
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it('t_ttl_rtt', () => {
|
|
216
|
-
jasmine.clock().tick(0); // 0
|
|
217
|
-
expect(Date.now()-T0).toBe(0)
|
|
218
|
-
|
|
219
|
-
expect( t_ttl_rtt(undefined, undefined) === undefined ).toBe(true);
|
|
220
|
-
expect( t_ttl_rtt(TTL_MSEC_1500) ).toBe(TTL_MSEC_1500 *2);
|
|
221
|
-
expect( t_ttl_rtt(TTL_MSEC_1500, 750*4) ).toBe(6000);
|
|
222
|
-
|
|
223
|
-
spyOn(console, "assert");
|
|
224
|
-
t_ttl_rtt(TTL_MSEC_1500, TTL_MSEC_1500 *2 +1); // 3001 > 2000 *2
|
|
225
|
-
expect(console.assert).toHaveBeenCalledWith(
|
|
226
|
-
false,
|
|
227
|
-
"t_ttl_rtt_: INVALID rtt_msec ttl_msec[1500] rtt_msec[3001]"
|
|
228
|
-
);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
// ,---, ___
|
|
234
|
-
// .' .' `\ ,--.'|_
|
|
235
|
-
// ,---.' \ | | :,'
|
|
236
|
-
// .--.--. | | .`\ | .--.--. : : ' :
|
|
237
|
-
// ,--.--. / / ' : : | ' | / / '.;__,' /
|
|
238
|
-
// / \ | : /`./ | ' ' ; :| : /`./| | |
|
|
239
|
-
// .--. .-. | | : ;_ ' | ; . || : ;_ :__,'| :
|
|
240
|
-
// \__\/: . . \ \ `. | | : | ' \ \ `. ' : |__
|
|
241
|
-
// ," .--.; | `----. \ ' : | / ; `----. \| | '.'|
|
|
242
|
-
// / / ,. | / /`--' / | | '` ,/ / /`--' /; : ;
|
|
243
|
-
// ; : .' \'--'. / ; : .' '--'. / | , /
|
|
244
|
-
// | , .-./ `--'---' | ,.' `--'---' ---`-'
|
|
245
|
-
// `--`---' '---'
|
|
246
|
-
//
|
|
247
|
-
|
|
248
|
-
describe('warp sequence as Destination receiver;', () => {
|
|
249
|
-
let callback_msgWarp;
|
|
250
|
-
let callback_msgEngage;
|
|
251
|
-
let callback_msg_sent_expired;
|
|
252
|
-
|
|
253
|
-
let json_msgWarp_src;
|
|
254
|
-
let str_msgWarp_src;
|
|
255
|
-
|
|
256
|
-
beforeEach(() => {
|
|
257
|
-
callback_msgWarp = jasmine.createSpy('callback_msgWarp').and.returnValue(true);
|
|
258
|
-
callback_msgEngage = jasmine.createSpy('callback_msgEngage').and.returnValue(true);
|
|
259
|
-
callback_msg_sent_expired = jasmine.createSpy('callback_msg_sent_expired');
|
|
260
|
-
|
|
261
|
-
twoPhW.config.receiver( callback_msgWarp, callback_msgEngage, callback_msg_sent_expired )
|
|
262
|
-
LOGR_.toggle(l_, {
|
|
263
|
-
// RECVER : 1,
|
|
264
|
-
// PROTOCOL_STATE : 1,
|
|
265
|
-
// DROPS : 1
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
expect(Date.now()-T0).toBe(0);
|
|
269
|
-
|
|
270
|
-
json_msgWarp_src= JSON_MsgWarp.create_with_id_user_hyperport(uuidv4(), '', '', TTL_MSEC_1500);
|
|
271
|
-
json_msgWarp_src.referer= karr_referer_src;
|
|
272
|
-
str_msgWarp_src = JSON.stringify(json_msgWarp_src);
|
|
273
|
-
|
|
274
|
-
jasmine.clock().tick(STT_MSEC_1000);
|
|
275
|
-
expect(eventLog.arr_events.length).toBe(0);
|
|
276
|
-
expect(callback_msgWarp).not.toHaveBeenCalled();
|
|
277
|
-
|
|
278
|
-
expect(Date.now()-T0).toBe(1000);
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
afterEach(() => {
|
|
282
|
-
logr_.log(l_.LOG_TEST, () => ['afterEach: eventLog.arr_events', eventLog.arr_events])
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
it('receive JSON_MsgWarp', () => {
|
|
286
|
-
jasmine.clock().tick(TTL_MSEC_1500 -STT_MSEC_1000 -1); // 1499
|
|
287
|
-
twoPhW.handler_json_msg(str_msgWarp_src, json_msgWarp_src);
|
|
288
|
-
expect(callback_msgWarp).toHaveBeenCalled();
|
|
289
|
-
expect(eventLog.arr_events.length).toBe(1);
|
|
290
|
-
expect(eventLog.arr_events[0].type).toBe('2PhW[JSON_MsgWarp]');
|
|
291
|
-
expect(eventLog.arr_events[0].data).toEqual({ msg : str_msgWarp_src, json_msg: json_msgWarp_src });
|
|
292
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateWarp).toBe(true);
|
|
293
|
-
|
|
294
|
-
// dup
|
|
295
|
-
twoPhW.handler_json_msg(str_msgWarp_src, json_msgWarp_src);
|
|
296
|
-
expect(eventLog.arr_events.length).toBe(1);
|
|
297
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateWarp).toBe(true);
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
it('receive JSON_MsgWarp expired', () => {
|
|
301
|
-
jasmine.clock().tick(TTL_MSEC_1500 -STT_MSEC_1000); // 1500
|
|
302
|
-
twoPhW.handler_json_msg(str_msgWarp_src, json_msgWarp_src);
|
|
303
|
-
expect(callback_msgWarp).not.toHaveBeenCalled();
|
|
304
|
-
expect(eventLog.arr_events.length).toBe(0);
|
|
305
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateInitialState).toBe(true);
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
it('receive premature JSON_MsgEngage', () => {
|
|
309
|
-
const json_msgEngage_recvd= JSON_MsgEngage.create_with_Warp(json_msgWarp_src);
|
|
310
|
-
json_msgEngage_recvd.referer= karr_referer_src;
|
|
311
|
-
|
|
312
|
-
twoPhW.handler_json_msgEffect(json_msgEngage_recvd, json_msgEngage_recvd);
|
|
313
|
-
expect(eventLog.arr_events.length).toBe(0);
|
|
314
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateInitialState).toBe(true);
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
it('traverse_State JSON_MsgWarp.compare(json_msgWarp, this._warp(json_msg).json_msgWarp )', () => {
|
|
318
|
-
twoPhW.handler_json_msg(str_msgWarp_src, json_msgWarp_src);
|
|
319
|
-
expect(eventLog.arr_events.length).toBe(1);
|
|
320
|
-
expect(eventLog.arr_events[0].type).toBe('2PhW[JSON_MsgWarp]');
|
|
321
|
-
expect(eventLog.arr_events[0].data).toEqual({ msg : str_msgWarp_src, json_msg: json_msgWarp_src });
|
|
322
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateWarp).toBe(true);
|
|
323
|
-
|
|
324
|
-
const json_msgWarp_wrong_dt= {
|
|
325
|
-
...json_msgWarp_src
|
|
326
|
-
};
|
|
327
|
-
jasmine.clock().tick(1); // 1001, make sure it is th wrong date
|
|
328
|
-
json_msgWarp_wrong_dt.dt= new Date().toISOString();
|
|
329
|
-
twoPhW.handler_json_msg(json_msgWarp_wrong_dt, json_msgWarp_wrong_dt);
|
|
330
|
-
expect(eventLog.arr_events.length).toBe(1);
|
|
331
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateWarp).toBe(true);
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
describe('warp sequence as Destination receiver;', () => {
|
|
335
|
-
let json_msgAckWarp_dst;
|
|
336
|
-
let str_msgAckWarp_dst;
|
|
337
|
-
let json_msgNackWarp_dst;
|
|
338
|
-
let str_msgNackWarp_dst;
|
|
339
|
-
|
|
340
|
-
beforeEach(() => {
|
|
341
|
-
json_msgAckWarp_dst= JSON_MsgAckWarp.create_with_Warp_Ok(json_msgWarp_src, true);
|
|
342
|
-
json_msgAckWarp_dst.referer= karr_referer_dst;
|
|
343
|
-
str_msgAckWarp_dst = JSON.stringify(json_msgAckWarp_dst);
|
|
344
|
-
|
|
345
|
-
json_msgNackWarp_dst= JSON_MsgAckWarp.create_with_Warp_Ok(json_msgWarp_src, false);
|
|
346
|
-
json_msgNackWarp_dst.referer= karr_referer_dst;
|
|
347
|
-
str_msgNackWarp_dst = JSON.stringify(str_msgNackWarp_dst);
|
|
348
|
-
|
|
349
|
-
expect(eventLog.arr_events.length).toBe(0);
|
|
350
|
-
|
|
351
|
-
expect(Date.now()-T0).toBe(STT_MSEC_1000);
|
|
352
|
-
|
|
353
|
-
twoPhW.handler_json_msg(str_msgWarp_src, json_msgWarp_src);
|
|
354
|
-
expect(callback_msgWarp).toHaveBeenCalled();
|
|
355
|
-
expect(eventLog.arr_events.length).toBe(1);
|
|
356
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateWarp).toBe(true);
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
it('Ack expires', () => {
|
|
360
|
-
jasmine.clock().tick(300); // register of Ack 300ms after creation
|
|
361
|
-
expect(Date.now()-T0).toBe(STT_MSEC_1000 +300);
|
|
362
|
-
twoPhW.register_msgAckWarp(str_msgAckWarp_dst, json_msgAckWarp_dst);
|
|
363
|
-
|
|
364
|
-
// The Ack gets to live for THE ACK'S creation time + TTL*2 + STT
|
|
365
|
-
// - Ack creation time @1000ms
|
|
366
|
-
// - TTL= 1500; TTL*2= 3000; STT=1000; timeout= 4000
|
|
367
|
-
// - expires at 5000
|
|
368
|
-
|
|
369
|
-
jasmine.clock().tick(TTL_MSEC_1500*2 + STT_MSEC_1000 -300 -1);
|
|
370
|
-
expect(Date.now()-T0).toBe( t_ttl_rtt(TTL_MSEC_1500, RTT_MSEC_2000) -1);
|
|
371
|
-
expect(callback_msg_sent_expired).not.toHaveBeenCalled();
|
|
372
|
-
|
|
373
|
-
jasmine.clock().tick(1); // t_ttl_rtt(TTL_MSEC_1500, RTT_MSEC_2000)
|
|
374
|
-
expect(Date.now()-T0).toBe(5000);
|
|
375
|
-
expect(callback_msg_sent_expired).toHaveBeenCalled();
|
|
376
|
-
expect(eventLog.arr_events.length).toBe(2);
|
|
377
|
-
expect(eventLog.arr_events[1].type).toBe('2PhW[JSON_MsgAckWarp]');
|
|
378
|
-
expect(eventLog.arr_events[1].data).toEqual({ msg: str_msgAckWarp_dst, json_msg : json_msgAckWarp_dst });
|
|
379
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateAckWarp).toBe(true);
|
|
380
|
-
|
|
381
|
-
const json_msgEngage_src= JSON_MsgEngage.create_with_Warp(json_msgWarp_src);
|
|
382
|
-
json_msgEngage_src.referer= karr_referer_src;
|
|
383
|
-
|
|
384
|
-
twoPhW.handler_json_msgEffect(json_msgEngage_src, json_msgEngage_src);
|
|
385
|
-
expect(eventLog.arr_events.length).toBe(2);
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
it('NACK', () => {
|
|
389
|
-
twoPhW.register_msgAckWarp(str_msgNackWarp_dst, json_msgNackWarp_dst);
|
|
390
|
-
expect(eventLog.arr_events.length).toBe(2);
|
|
391
|
-
expect(eventLog.arr_events[1].type).toBe('2PhW[JSON_MsgAckWarp]');
|
|
392
|
-
expect(eventLog.arr_events[1].data).toEqual({ msg : str_msgNackWarp_dst, json_msg : json_msgNackWarp_dst });
|
|
393
|
-
|
|
394
|
-
jasmine.clock().tick(STT_MSEC_1000); // 2000, STT_MSEC_1000 *2= RTT
|
|
395
|
-
const json_msgEngage_src= JSON_MsgEngage.create_with_Warp(json_msgWarp_src);
|
|
396
|
-
json_msgEngage_src.referer= karr_referer_src;
|
|
397
|
-
|
|
398
|
-
jasmine.clock().tick(STT_MSEC_1000); // 3000, STT_MSEC_1000 *3
|
|
399
|
-
twoPhW.handler_json_msgEffect(json_msgEngage_src, json_msgEngage_src);
|
|
400
|
-
expect(eventLog.arr_events.length).toBe(2);
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
describe('JSON_MsgAckWarp;', () => {
|
|
404
|
-
let json_msgEngage_src;
|
|
405
|
-
let str_msgEngage_src;
|
|
406
|
-
|
|
407
|
-
beforeEach(() => {
|
|
408
|
-
LOGR_.toggle(l_, {
|
|
409
|
-
// RECVER : 1,
|
|
410
|
-
// PROTOCOL_STATE : 1,
|
|
411
|
-
// DROPS : 1,
|
|
412
|
-
// LOG_TEST : true
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
jasmine.clock().tick(0);
|
|
416
|
-
expect(Date.now()-T0).toBe(STT_MSEC_1000);
|
|
417
|
-
|
|
418
|
-
// Ack
|
|
419
|
-
twoPhW.register_msgAckWarp(str_msgAckWarp_dst, json_msgAckWarp_dst);
|
|
420
|
-
expect(eventLog.arr_events.length).toBe(2);
|
|
421
|
-
expect(eventLog.arr_events[1].type).toBe('2PhW[JSON_MsgAckWarp]');
|
|
422
|
-
expect(eventLog.arr_events[1].data).toEqual({ msg: str_msgAckWarp_dst, json_msg : json_msgAckWarp_dst });
|
|
423
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateAckWarp).toBe(true);
|
|
424
|
-
|
|
425
|
-
jasmine.clock().tick(STT_MSEC_1000); // STT_MSEC_1000 *2= RTT
|
|
426
|
-
json_msgEngage_src= JSON_MsgEngage.create_with_Warp(json_msgWarp_src);
|
|
427
|
-
json_msgEngage_src.referer= karr_referer_src;
|
|
428
|
-
str_msgEngage_src = JSON.stringify(json_msgEngage_src);
|
|
429
|
-
|
|
430
|
-
expect(Date.now()-T0).toBe(RTT_MSEC_2000);
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
// The Ack gets to live for THE ACK'S creation time + TTL*2
|
|
434
|
-
// - Ack creation time @1000ms
|
|
435
|
-
// - TTL= 1500; TTL*2= 3000; timeout= 3000
|
|
436
|
-
// - expires at 4000
|
|
437
|
-
|
|
438
|
-
it('AckWarp and JSON_MsgEngage timeouts', () => {
|
|
439
|
-
jasmine.clock().tick(t_ttl_rtt(TTL_MSEC_1500) -1);
|
|
440
|
-
expect(Date.now()-T0).toBe( t_ttl_rtt(TTL_MSEC_1500, RTT_MSEC_2000) -1);
|
|
441
|
-
expect(callback_msg_sent_expired).not.toHaveBeenCalled();
|
|
442
|
-
expect(callback_msgEngage).not.toHaveBeenCalled();
|
|
443
|
-
|
|
444
|
-
jasmine.clock().tick(1);
|
|
445
|
-
expect(Date.now()-T0).toBe( t_ttl_rtt(TTL_MSEC_1500, RTT_MSEC_2000));
|
|
446
|
-
expect(callback_msg_sent_expired).toHaveBeenCalled();
|
|
447
|
-
|
|
448
|
-
expect( t_ttl_rtt(TTL_MSEC_1500, RTT_MSEC_2000) === 5000 ).toBe(true);
|
|
449
|
-
// The Engaget gets to live for THE WARP'S creation time + TTL*2 + RTT
|
|
450
|
-
// - the Warp was created time at 0ms
|
|
451
|
-
// - TTL= 1500, RTT= 2000; TTL*2 + RTT= 5000; timeout= 5000
|
|
452
|
-
// - expires at 5000
|
|
453
|
-
|
|
454
|
-
twoPhW.handler_json_msgEffect(str_msgEngage_src, json_msgEngage_src);
|
|
455
|
-
expect(callback_msgEngage).not.toHaveBeenCalled();
|
|
456
|
-
expect(eventLog.arr_events.length).toBe(2);
|
|
457
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateAckWarp).toBe(true);
|
|
458
|
-
|
|
459
|
-
jasmine.clock().tick(STT_MSEC_1000); // 4000, STT_MSEC_1000 *4
|
|
460
|
-
const json_msgNackEngage_dst= JSON_MsgAckEngage.create_with_Engage_Ok(json_msgEngage_src, false);
|
|
461
|
-
json_msgNackEngage_dst.referer= karr_referer_dst;
|
|
462
|
-
twoPhW.register_msgAckEngage(JSON.stringify(json_msgNackEngage_dst), json_msgNackEngage_dst)
|
|
463
|
-
expect(eventLog.arr_events.length).toBe(2);
|
|
464
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateAckWarp).toBe(true);
|
|
465
|
-
});
|
|
466
|
-
|
|
467
|
-
describe('JSON_MsgAckWarp;', () => {
|
|
468
|
-
let json_msgNackEngage_dst;
|
|
469
|
-
let str_msgNackEngage_dst;
|
|
470
|
-
|
|
471
|
-
beforeEach(() => {
|
|
472
|
-
LOGR_.toggle(l_, {
|
|
473
|
-
// RECVER : 1,
|
|
474
|
-
// PROTOCOL_STATE : 1,
|
|
475
|
-
// DROPS : 1
|
|
476
|
-
});
|
|
477
|
-
|
|
478
|
-
jasmine.clock().tick(STT_MSEC_1000); // 3000, STT_MSEC_1000 *3
|
|
479
|
-
|
|
480
|
-
twoPhW.handler_json_msgEffect(str_msgEngage_src, json_msgEngage_src);
|
|
481
|
-
expect(callback_msgEngage).toHaveBeenCalled();
|
|
482
|
-
expect(callback_msg_sent_expired).not.toHaveBeenCalled();
|
|
483
|
-
expect(eventLog.arr_events.length).toBe(3);
|
|
484
|
-
expect(eventLog.arr_events[2].type).toBe('2PhW[JSON_MsgEngage]');
|
|
485
|
-
expect(eventLog.arr_events[2].data).toEqual({ msg: str_msgEngage_src, json_msg : json_msgEngage_src });
|
|
486
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateEngage).toBe(true);
|
|
487
|
-
|
|
488
|
-
json_msgNackEngage_dst= JSON_MsgAckEngage.create_with_Engage_Ok(json_msgEngage_src, false);
|
|
489
|
-
json_msgNackEngage_dst.referer= karr_referer_dst;
|
|
490
|
-
str_msgNackEngage_dst = JSON.stringify(json_msgNackEngage_dst);
|
|
491
|
-
|
|
492
|
-
// jasmine.clock().tick(STT_MSEC_1000); // 4000, STT_MSEC_1000 *4
|
|
493
|
-
// expect(Date.now()-T0).toBe(RTT_MSEC_2000 *2);
|
|
494
|
-
expect(Date.now()-T0).toBe(STT_MSEC_1000 *3);
|
|
495
|
-
});
|
|
496
|
-
|
|
497
|
-
it('JSON_MsgAckEngage', () => {
|
|
498
|
-
expect( t_ttl_rtt(TTL_MSEC_1500, RTT_MSEC_2000) === 5000 ).toBe(true);
|
|
499
|
-
// The Engaget gets to live for THE WARP'S creation time + TTL*2 + RTT
|
|
500
|
-
// - the Warp was created time at 0ms
|
|
501
|
-
// - TTL= 1500, RTT= 2000; TTL*2 + RTT= 5000; timeout= 5000
|
|
502
|
-
// - expires at 5000
|
|
503
|
-
jasmine.clock().tick(2000 -1);
|
|
504
|
-
expect(Date.now()-T0).toBe( t_ttl_rtt(TTL_MSEC_1500, RTT_MSEC_2000) -1);
|
|
505
|
-
|
|
506
|
-
twoPhW.register_msgAckEngage(str_msgNackEngage_dst, json_msgNackEngage_dst)
|
|
507
|
-
expect(eventLog.arr_events.length).toBe(4);
|
|
508
|
-
expect(eventLog.arr_events[3].type).toBe('2PhW[JSON_MsgAckEngage]');
|
|
509
|
-
expect(eventLog.arr_events[3].data).toEqual({ msg : str_msgNackEngage_dst, json_msg : json_msgNackEngage_dst });
|
|
510
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateAckEngage).toBe(true);
|
|
511
|
-
});
|
|
512
|
-
|
|
513
|
-
it('JSON_MsgAckEngage, expired', () => {
|
|
514
|
-
jasmine.clock().tick(2000);
|
|
515
|
-
expect(Date.now()-T0).toBe(t_ttl_rtt(TTL_MSEC_1500, RTT_MSEC_2000));
|
|
516
|
-
|
|
517
|
-
twoPhW.register_msgAckEngage(str_msgNackEngage_dst, json_msgNackEngage_dst)
|
|
518
|
-
expect(eventLog.arr_events.length).toBe(3);
|
|
519
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateEngage).toBe(true);
|
|
520
|
-
});
|
|
521
|
-
|
|
522
|
-
});
|
|
523
|
-
});
|
|
524
|
-
});
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
it('JSON_MsgWarp instantaneous', () => {
|
|
528
|
-
// const callback_msgWarp= (_msg, json_msgWarp) => {
|
|
529
|
-
// // console.log('callback_msgWarp', json_msgWarp);
|
|
530
|
-
|
|
531
|
-
// const json_msgAckWarp= JSON_MsgAckWarp.create_with_msgOk(json_msgWarp, true);
|
|
532
|
-
// json_msgAckWarp.referer= karr_referer_dst;
|
|
533
|
-
// expect((twoPhW.eventLog.traverse_State(json_msgWarp_recvd)).state instanceof StateWarp).toBe(true);
|
|
534
|
-
|
|
535
|
-
// twoPhW.eventLog.addEvent(json_msgAckWarp);
|
|
536
|
-
// expect(eventLog.arr_events.length).toBe(2);
|
|
537
|
-
// expect(eventLog.arr_events[1].type).toBe('2PhW[JSON_MsgAckWarp]');
|
|
538
|
-
// expect(eventLog.arr_events[1].data).toBe(json_msgAckWarp);
|
|
539
|
-
|
|
540
|
-
// return true;
|
|
541
|
-
// }
|
|
542
|
-
|
|
543
|
-
// twoPhW.config.receiver( callback_msgWarp, () => {} )
|
|
544
|
-
// twoPhW.config.toggled= {
|
|
545
|
-
// // RECVER : 1,
|
|
546
|
-
// // PROTOCOL_STATE : 1,
|
|
547
|
-
// // DROPS : 1
|
|
548
|
-
// }
|
|
549
|
-
|
|
550
|
-
// const json_msgWarp_recvd= JSON_MsgWarp.create_with_id_user_hyperport(uuidv4(), '', '', TIMEOUT_2000_MSEC);
|
|
551
|
-
// json_msgWarp_recvd.warp.instantaneous= true;
|
|
552
|
-
// json_msgWarp_recvd.referer= karr_referer_src;
|
|
553
|
-
|
|
554
|
-
// const json_msgEngage_recvd= JSON_MsgEngage.create_with_MsgWarp(json_msgWarp_recvd);
|
|
555
|
-
// json_msgEngage_recvd.referer= karr_referer_src;
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
// jasmine.clock().tick(1000); // 1000
|
|
559
|
-
// twoPhW.handler_json(json_msgWarp_recvd, json_msgWarp_recvd);
|
|
560
|
-
// expect(eventLog.arr_events[0].type).toBe('2PhW[JSON_MsgWarp]');
|
|
561
|
-
// expect(eventLog.arr_events[0].data).toBe(json_msgWarp_recvd);
|
|
562
|
-
// expect((twoPhW.eventLog.traverse_State(json_msgWarp_recvd)).state instanceof StateAckWarp).toBe(true);
|
|
563
|
-
|
|
564
|
-
// jasmine.clock().tick(1000); // 2000
|
|
565
|
-
// twoPhW.handler_json(json_msgEngage_recvd, json_msgEngage_recvd);
|
|
566
|
-
|
|
567
|
-
// expect(eventLog.arr_events.length).toBe(3);
|
|
568
|
-
// expect(eventLog.arr_events[2].type).toBe('2PhW[DROPPED!]');
|
|
569
|
-
});
|
|
570
|
-
|
|
571
|
-
});
|
|
572
|
-
|
|
573
|
-
// .--.--.
|
|
574
|
-
// / / '.
|
|
575
|
-
// | : /`. / __ ,-.
|
|
576
|
-
// .--.--. ; | |--` ,' ,'/ /|
|
|
577
|
-
// ,--.--. / / ' | : ;_ ' | |' | ,---.
|
|
578
|
-
// / \ | : /`./ \ \ `. | | ,'/ \
|
|
579
|
-
// .--. .-. | | : ;_ `----. \' : / / / '
|
|
580
|
-
// \__\/: . . \ \ `. __ \ \ || | ' . ' /
|
|
581
|
-
// ," .--.; | `----. \ / /`--' /; : | ' ; :__
|
|
582
|
-
// / / ,. | / /`--' / '--'. / | , ; ' | '.'|
|
|
583
|
-
// ; : .' \'--'. / `--'---' ---' | : :
|
|
584
|
-
// | , .-./ `--'---' \ \ /
|
|
585
|
-
// `--`---' `----'
|
|
586
|
-
//
|
|
587
|
-
|
|
588
|
-
describe('warp sequence as Source sender;', () => {
|
|
589
|
-
let callback_msgAckWarp;
|
|
590
|
-
let callback_msgAckEngage;
|
|
591
|
-
let callback_msg_sent_expired;
|
|
592
|
-
|
|
593
|
-
let json_msgWarp_src;
|
|
594
|
-
let str_msgWarp_src;
|
|
595
|
-
|
|
596
|
-
beforeEach(() => {
|
|
597
|
-
callback_msgAckWarp = jasmine.createSpy('callback_msgAckWarp').and.returnValue(true);
|
|
598
|
-
callback_msgAckEngage = jasmine.createSpy('callback_msgAckEngage').and.returnValue(true);
|
|
599
|
-
callback_msg_sent_expired = jasmine.createSpy('callback_msg_sent_expired');
|
|
600
|
-
twoPhW.config.sender( callback_msgAckWarp, callback_msgAckEngage, callback_msg_sent_expired )
|
|
601
|
-
LOGR_.toggle(l_, {
|
|
602
|
-
// SENDER : 1,
|
|
603
|
-
// PROTOCOL_STATE : 1,
|
|
604
|
-
// DROPS : 1
|
|
605
|
-
});
|
|
606
|
-
|
|
607
|
-
jasmine.clock().tick(0);
|
|
608
|
-
expect(Date.now()-T0).toBe(0);
|
|
609
|
-
|
|
610
|
-
json_msgWarp_src= JSON_MsgWarp.create_with_id_user_hyperport(uuidv4(), '', '', TTL_MSEC_1500);
|
|
611
|
-
json_msgWarp_src.referer= karr_referer_src;
|
|
612
|
-
str_msgWarp_src = JSON.stringify(json_msgWarp_src);
|
|
613
|
-
|
|
614
|
-
expect(eventLog.arr_events.length).toBe(0);
|
|
615
|
-
});
|
|
616
|
-
|
|
617
|
-
afterEach(() => {
|
|
618
|
-
logr_.log(l_.LOG_TEST, () => ['afterEach: eventLog.arr_events', eventLog.arr_events])
|
|
619
|
-
});
|
|
620
|
-
|
|
621
|
-
it('send JSON_MsgWarp == can register a Warp', () => {
|
|
622
|
-
jasmine.clock().tick(TTL_MSEC_1500 -1);
|
|
623
|
-
expect(Date.now()-T0).toBe(1499);
|
|
624
|
-
|
|
625
|
-
twoPhW.register_msgWarp(str_msgWarp_src, json_msgWarp_src);
|
|
626
|
-
expect(eventLog.arr_events.length).toBe(1);
|
|
627
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateWarp).toBe(true);
|
|
628
|
-
|
|
629
|
-
jasmine.clock().tick(TTL_MSEC_1500 +1);
|
|
630
|
-
expect(Date.now()-T0).toBe(t_ttl_rtt(TTL_MSEC_1500));
|
|
631
|
-
expect(callback_msg_sent_expired).toHaveBeenCalled();
|
|
632
|
-
});
|
|
633
|
-
|
|
634
|
-
it('send JSON_MsgWarp == cant register an expired Warp', () => {
|
|
635
|
-
jasmine.clock().tick(TTL_MSEC_1500);
|
|
636
|
-
expect(Date.now()-T0).toBe(1500);
|
|
637
|
-
|
|
638
|
-
twoPhW.register_msgWarp(str_msgWarp_src, json_msgWarp_src);
|
|
639
|
-
expect(eventLog.arr_events.length).toBe(0);
|
|
640
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateInitialState).toBe(true);
|
|
641
|
-
});
|
|
642
|
-
|
|
643
|
-
describe('JSON_MsgAckWarp;', () => {
|
|
644
|
-
let json_msgAckWarp_dst;
|
|
645
|
-
let str_msgAckWarp_dst;
|
|
646
|
-
let json_msgNackWarp_dst;
|
|
647
|
-
let str_msgNackWarp_dst;
|
|
648
|
-
let json_msgEngage_src;
|
|
649
|
-
let str_msgEngage_src;
|
|
650
|
-
|
|
651
|
-
beforeEach(() => {
|
|
652
|
-
LOGR_.toggle(l_, {
|
|
653
|
-
// SENDER : 1,
|
|
654
|
-
// PROTOCOL_STATE : 1,
|
|
655
|
-
// DROPS : 1
|
|
656
|
-
});
|
|
657
|
-
|
|
658
|
-
twoPhW.register_msgWarp(str_msgWarp_src, json_msgWarp_src);
|
|
659
|
-
expect(eventLog.arr_events.length).toBe(1);
|
|
660
|
-
expect(eventLog.arr_events[0].type).toBe('2PhW[JSON_MsgWarp]');
|
|
661
|
-
expect(eventLog.arr_events[0].data).toEqual({ msg : str_msgWarp_src, json_msg: json_msgWarp_src });
|
|
662
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateWarp).toBe(true);
|
|
663
|
-
|
|
664
|
-
expect(Date.now()-T0).toBe(0);
|
|
665
|
-
|
|
666
|
-
jasmine.clock().tick(STT_MSEC_1000); // 1000
|
|
667
|
-
json_msgAckWarp_dst= JSON_MsgAckWarp.create_with_Warp_Ok(json_msgWarp_src, true);
|
|
668
|
-
json_msgAckWarp_dst.referer= karr_referer_dst;
|
|
669
|
-
str_msgAckWarp_dst = JSON.stringify(json_msgAckWarp_dst);
|
|
670
|
-
|
|
671
|
-
json_msgNackWarp_dst= JSON_MsgAckWarp.create_with_Warp_Ok(json_msgWarp_src, false);
|
|
672
|
-
json_msgNackWarp_dst.referer= karr_referer_dst;
|
|
673
|
-
str_msgNackWarp_dst = JSON.stringify(json_msgNackWarp_dst);
|
|
674
|
-
|
|
675
|
-
jasmine.clock().tick(STT_MSEC_1000); // 2000
|
|
676
|
-
|
|
677
|
-
json_msgEngage_src= JSON_MsgEngage.create_with_Warp(json_msgWarp_src);
|
|
678
|
-
json_msgEngage_src.referer= karr_referer_src;
|
|
679
|
-
str_msgEngage_src = JSON.stringify(json_msgEngage_src);
|
|
680
|
-
|
|
681
|
-
expect(Date.now()-T0).toBe(STT_MSEC_1000 *2);
|
|
682
|
-
expect(Date.now()-T0).toBe(RTT_MSEC_2000);
|
|
683
|
-
});
|
|
684
|
-
|
|
685
|
-
it('Late Ack', () => {
|
|
686
|
-
expect(t_ttl_rtt(TTL_MSEC_1500) === 3000).toBe(true)
|
|
687
|
-
|
|
688
|
-
jasmine.clock().tick(1000 -1); // 2999
|
|
689
|
-
expect(Date.now()-T0).toBe(t_ttl_rtt(TTL_MSEC_1500) -1);
|
|
690
|
-
|
|
691
|
-
expect(callback_msgAckWarp).not.toHaveBeenCalled();
|
|
692
|
-
expect(callback_msg_sent_expired).not.toHaveBeenCalled();
|
|
693
|
-
|
|
694
|
-
jasmine.clock().tick(1); // 3000
|
|
695
|
-
expect(callback_msgAckWarp).not.toHaveBeenCalled();
|
|
696
|
-
expect(callback_msg_sent_expired).toHaveBeenCalled();
|
|
697
|
-
|
|
698
|
-
twoPhW.handler_json_msgAck(json_msgAckWarp_dst, json_msgAckWarp_dst);
|
|
699
|
-
expect(callback_msgAckWarp).not.toHaveBeenCalled();
|
|
700
|
-
expect(eventLog.arr_events.length).toBe(1);
|
|
701
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateWarp).toBe(true);
|
|
702
|
-
});
|
|
703
|
-
|
|
704
|
-
it('send JSON_MsgWarp == NACK', () => {
|
|
705
|
-
twoPhW.handler_json_msgAck(str_msgNackWarp_dst, json_msgNackWarp_dst);
|
|
706
|
-
expect(eventLog.arr_events.length).toBe(2);
|
|
707
|
-
expect(eventLog.arr_events[1].type).toBe('2PhW[JSON_MsgAckWarp]');
|
|
708
|
-
expect(eventLog.arr_events[1].data).toEqual({msg : str_msgNackWarp_dst, json_msg : json_msgNackWarp_dst });
|
|
709
|
-
expect(callback_msgAckWarp).toHaveBeenCalled();
|
|
710
|
-
|
|
711
|
-
twoPhW.register_msgEngage(str_msgEngage_src, json_msgEngage_src);
|
|
712
|
-
expect(eventLog.arr_events.length).toBe(2);
|
|
713
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateAckWarp).toBe(true);
|
|
714
|
-
|
|
715
|
-
jasmine.clock().tick(STT_MSEC_1000); // 3000
|
|
716
|
-
const json_msgAckEngage_recv= JSON_MsgAckEngage.create_with_Engage_Ok(json_msgEngage_src, true);
|
|
717
|
-
json_msgAckEngage_recv.referer= karr_referer_dst;
|
|
718
|
-
|
|
719
|
-
jasmine.clock().tick(STT_MSEC_1000); // 4000
|
|
720
|
-
twoPhW.handler_json_msgAck(json_msgAckEngage_recv, json_msgAckEngage_recv);
|
|
721
|
-
expect(eventLog.arr_events.length).toBe(2);
|
|
722
|
-
});
|
|
723
|
-
|
|
724
|
-
describe('register Engage!', () => {
|
|
725
|
-
beforeEach(() => {
|
|
726
|
-
LOGR_.toggle(l_, {
|
|
727
|
-
// SENDER : 1,
|
|
728
|
-
// PROTOCOL_STATE : 1,
|
|
729
|
-
// DROPS : 1
|
|
730
|
-
});
|
|
731
|
-
|
|
732
|
-
expect(Date.now()-T0).toBe(RTT_MSEC_2000);
|
|
733
|
-
|
|
734
|
-
twoPhW.handler_json_msgAck(str_msgAckWarp_dst, json_msgAckWarp_dst);
|
|
735
|
-
expect(callback_msgAckWarp).toHaveBeenCalled();
|
|
736
|
-
expect(eventLog.arr_events.length).toBe(2);
|
|
737
|
-
expect(eventLog.arr_events[1].type).toBe('2PhW[JSON_MsgAckWarp]');
|
|
738
|
-
expect(eventLog.arr_events[1].data).toEqual({ msg: str_msgAckWarp_dst, json_msg : json_msgAckWarp_dst });
|
|
739
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateAckWarp).toBe(true);
|
|
740
|
-
});
|
|
741
|
-
|
|
742
|
-
it('CAN register a Engage', () => {
|
|
743
|
-
expect(t_ttl_rtt(TTL_MSEC_1500, RTT_MSEC_2000) === 5000).toBe(true)
|
|
744
|
-
jasmine.clock().tick(TTL_MSEC_1500*2 -1); // 4999
|
|
745
|
-
expect(Date.now()-T0).toBe(4999);
|
|
746
|
-
|
|
747
|
-
twoPhW.register_msgEngage(str_msgEngage_src, json_msgEngage_src);
|
|
748
|
-
expect(eventLog.arr_events.length).toBe(3);
|
|
749
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateEngage).toBe(true);
|
|
750
|
-
});
|
|
751
|
-
|
|
752
|
-
it('delayed register of Engage', () => {
|
|
753
|
-
expect(t_ttl_rtt(TTL_MSEC_1500, RTT_MSEC_2000) === 5000).toBe(true)
|
|
754
|
-
jasmine.clock().tick(300);
|
|
755
|
-
expect(Date.now()-T0).toBe(RTT_MSEC_2000 +300);
|
|
756
|
-
twoPhW.register_msgEngage(str_msgEngage_src, json_msgEngage_src);
|
|
757
|
-
expect(eventLog.arr_events.length).toBe(3);
|
|
758
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateEngage).toBe(true);
|
|
759
|
-
|
|
760
|
-
jasmine.clock().tick( t_ttl_rtt(TTL_MSEC_1500) -300 -1); // 4999
|
|
761
|
-
expect(Date.now()-T0).toBe(4999);
|
|
762
|
-
expect(callback_msg_sent_expired).not.toHaveBeenCalled();
|
|
763
|
-
|
|
764
|
-
jasmine.clock().tick(1);
|
|
765
|
-
expect(callback_msg_sent_expired).toHaveBeenCalled();
|
|
766
|
-
});
|
|
767
|
-
|
|
768
|
-
it('can NOT register an expired Engage', () => {
|
|
769
|
-
expect(t_ttl_rtt(TTL_MSEC_1500, RTT_MSEC_2000) === 5000).toBe(true)
|
|
770
|
-
jasmine.clock().tick(TTL_MSEC_1500*2); // 5000
|
|
771
|
-
twoPhW.register_msgEngage(str_msgEngage_src, json_msgEngage_src);
|
|
772
|
-
expect(eventLog.arr_events.length).toBe(2);
|
|
773
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateAckWarp).toBe(true);
|
|
774
|
-
});
|
|
775
|
-
|
|
776
|
-
describe('Engage!', () => {
|
|
777
|
-
let json_msgAckEngage_dst;
|
|
778
|
-
let str_msgAckEngage_dst;
|
|
779
|
-
|
|
780
|
-
beforeEach(() => {
|
|
781
|
-
LOGR_.toggle(l_, {
|
|
782
|
-
// SENDER : 1,
|
|
783
|
-
// PROTOCOL_STATE : 1,
|
|
784
|
-
// DROPS : 1
|
|
785
|
-
});
|
|
786
|
-
|
|
787
|
-
expect(Date.now()-T0).toBe(RTT_MSEC_2000);
|
|
788
|
-
|
|
789
|
-
twoPhW.register_msgEngage(str_msgEngage_src, json_msgEngage_src);
|
|
790
|
-
expect(eventLog.arr_events.length).toBe(3);
|
|
791
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateEngage).toBe(true);
|
|
792
|
-
|
|
793
|
-
jasmine.clock().tick(STT_MSEC_1000); // 3000
|
|
794
|
-
json_msgAckEngage_dst= JSON_MsgAckEngage.create_with_Engage_Ok(json_msgEngage_src, true);
|
|
795
|
-
json_msgAckEngage_dst.referer= karr_referer_dst;
|
|
796
|
-
str_msgAckEngage_dst = JSON.stringify(json_msgAckEngage_dst);
|
|
797
|
-
|
|
798
|
-
jasmine.clock().tick(STT_MSEC_1000); // 4000
|
|
799
|
-
expect(callback_msg_sent_expired).not.toHaveBeenCalled();
|
|
800
|
-
|
|
801
|
-
expect(Date.now()-T0).toBe(RTT_MSEC_2000 +(STT_MSEC_1000*2));
|
|
802
|
-
expect(Date.now()-T0).toBe(4000);
|
|
803
|
-
});
|
|
804
|
-
|
|
805
|
-
it('Ack', () => {
|
|
806
|
-
expect(t_ttl_rtt(TTL_MSEC_1500, RTT_MSEC_2000) === 5000).toBe(true)
|
|
807
|
-
|
|
808
|
-
jasmine.clock().tick(1000 -1); // 4999
|
|
809
|
-
expect(Date.now()-T0).toBe(4999);
|
|
810
|
-
expect(callback_msg_sent_expired).not.toHaveBeenCalled();
|
|
811
|
-
|
|
812
|
-
twoPhW.handler_json_msgAck(str_msgAckEngage_dst, json_msgAckEngage_dst);
|
|
813
|
-
expect(eventLog.arr_events.length).toBe(4);
|
|
814
|
-
expect(eventLog.arr_events[3].type).toBe('2PhW[JSON_MsgAckEngage]');
|
|
815
|
-
expect(eventLog.arr_events[3].data).toEqual({ msg: str_msgAckEngage_dst, json_msg : json_msgAckEngage_dst });
|
|
816
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateAckEngage).toBe(true);
|
|
817
|
-
|
|
818
|
-
jasmine.clock().tick(1); // 5000
|
|
819
|
-
expect(callback_msg_sent_expired).not.toHaveBeenCalled();
|
|
820
|
-
});
|
|
821
|
-
|
|
822
|
-
it('Ack (timed out)', () => {
|
|
823
|
-
expect(t_ttl_rtt(TTL_MSEC_1500, RTT_MSEC_2000) === 5000).toBe(true)
|
|
824
|
-
|
|
825
|
-
jasmine.clock().tick(1000); // 5000
|
|
826
|
-
expect(Date.now()-T0).toBe(t_ttl_rtt(TTL_MSEC_1500, RTT_MSEC_2000));
|
|
827
|
-
expect(callback_msg_sent_expired).toHaveBeenCalled();
|
|
828
|
-
|
|
829
|
-
// test to make sure a late ack isn't a valid AckEngage state
|
|
830
|
-
twoPhW.handler_json_msgAck(str_msgAckEngage_dst, json_msgAckEngage_dst);
|
|
831
|
-
expect(eventLog.arr_events.length).toBe(3);
|
|
832
|
-
expect((twoPhW.eventLog.traverse_State(json_msgWarp_src)).state instanceof StateEngage).toBe(true);
|
|
833
|
-
});
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
});
|
|
837
|
-
|
|
838
|
-
});
|
|
839
|
-
|
|
840
|
-
});
|
|
841
|
-
|
|
842
|
-
});
|
|
843
|
-
|
|
844
|
-
//TODO: check if multiple warps have been sent out with the same destination
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
});
|
|
849
|
-
|
|
850
|
-
//-------------------------------------------------------------------------------------------------
|