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