summaryrefslogtreecommitdiff
path: root/test/storage.test
blob: 0369807231edf62ab3165363be46d5a92fc494c2 (plain)
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
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
132
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
test Storage:
	spawn as p1

	# Root finding
	###############

	# Diamond history
	send to p1:
		"store rec"
		"text:t First root"
		""
	expect from p1:
		/store-done (blake2#[0-9a-f]*)/ capture r1
	guard (r1 == "blake2#c4a8c69fbc8398acf76a2ec1e5a191f339c4d03c3eb425af19d6d7d5efac6b8e")

	send to p1:
		"store rec"
		"PREV:r $r1"
		""
	expect from p1:
		/store-done (blake2#[0-9a-f]*)/ capture r2

	send to p1:
		"store rec"
		"text:t Second branch"
		"PREV:r $r1"
		""
	expect from p1:
		/store-done (blake2#[0-9a-f]*)/ capture r3

	send to p1:
		"store rec"
		"PREV:r $r2"
		"PREV:r $r3"
		""
	expect from p1:
		/store-done (blake2#[0-9a-f]*)/ capture r4

	send to p1 "stored-generation $r1"
	expect from p1 /stored-generation $r1 0/

	send to p1 "stored-generation $r2"
	expect from p1 /stored-generation $r2 1/

	send to p1 "stored-generation $r3"
	expect from p1 /stored-generation $r3 1/

	send to p1 "stored-generation $r4"
	expect from p1 /stored-generation $r4 2/

	send to p1 "stored-roots $r1"
	expect from p1 /stored-roots $r1 $r1/

	send to p1 "stored-roots $r2"
	expect from p1 /stored-roots $r2 $r1/

	send to p1 "stored-roots $r3"
	expect from p1 /stored-roots $r3 $r1/

	send to p1 "stored-roots $r4"
	expect from p1 /stored-roots $r4 $r1/

	# Attach second root
	send to p1:
		"store rec"
		"text:t Second root"
		""
	expect from p1:
		/store-done (blake2#[0-9a-f]*)/ capture r2_1

	send to p1:
		"store rec"
		"PREV:r $r2_1"
		""
	expect from p1:
		/store-done (blake2#[0-9a-f]*)/ capture r2_2

	send to p1:
		"store rec"
		"PREV:r $r2_2"
		"PREV:r $r4"
		""
	expect from p1:
		/store-done (blake2#[0-9a-f]*)/ capture r2_3

	send to p1 "stored-generation $r2_3"
	expect from p1 /stored-generation $r2_3 3/

	send to p1 "stored-generation $r2_2"
	expect from p1 /stored-generation $r2_2 1/

	send to p1 "stored-roots $r2_3"
	expect from p1 /stored-roots $r2_3 $r2_1 $r1/

	send to p1 "stored-roots $r2_2"
	expect from p1 /stored-roots $r2_2 $r2_1/


	# Set
	#####

	send to p1 "stored-set-add $r1"
	expect from p1 /stored-set-add (blake2#[0-9a-f]*)/ capture s1
	send to p1 "stored-set-add $r2 $s1"
	expect from p1 /stored-set-add (blake2#[0-9a-f]*)/ capture s2
	send to p1 "stored-set-add $r3 $s2"
	expect from p1 /stored-set-add (blake2#[0-9a-f]*)/ capture s3
	send to p1 "stored-set-add $r4 $s3"
	expect from p1 /stored-set-add (blake2#[0-9a-f]*)/ capture s4

	send to p1 "stored-set-list $s1"
	expect from p1:
		/stored-set-item $r1/
		/stored-set-(.*)/ capture done1
	guard (done1 == "done")

	send to p1 "stored-set-list $s2"
	expect from p1:
		/stored-set-item $r2/
		/stored-set-(.*)/ capture done2
	guard (done2 == "done")

	send to p1 "stored-set-list $s3"
	expect from p1:
		/stored-set-item $r2 $r3/
		/stored-set-(.*)/ capture done3
	guard (done3 == "done")

	send to p1 "stored-set-list $s4"
	expect from p1:
		/stored-set-item $r4/
		/stored-set-(.*)/ capture done4
	guard (done4 == "done")


	send to p1 "stored-set-add $r2_2 $s4"
	expect from p1 /stored-set-add (blake2#[0-9a-f]*)/ capture s5
	send to p1 "stored-set-add $r2_3 $s5"
	expect from p1 /stored-set-add (blake2#[0-9a-f]*)/ capture s6

	send to p1 "stored-set-list $s5"
	expect from p1:
		/stored-set-item $r4/
		/stored-set-item $r2_2/
		/stored-set-(.*)/ capture done5
	guard (done5 == "done")

	send to p1 "stored-set-list $s6"
	expect from p1:
		/stored-set-item $r2_3/
		/stored-set-(.*)/ capture done6
	guard (done6 == "done")


test StorageWatcher:
	spawn as p1
	spawn as p2 on p1.node

	send to p1:
		"store rec"
		"text:n 1"
		""
	expect from p1:
		/store-done (blake2#[0-9a-f]*)/ capture r1

	send to p1:
		"store rec"
		"text:n 2"
		""
	expect from p1:
		/store-done (blake2#[0-9a-f]*)/ capture r2

	send to p1:
		"store rec"
		"text:n 3"
		""
	expect from p1:
		/store-done (blake2#[0-9a-f]*)/ capture r3

	send to p1:
		"store rec"
		"text:n 4"
		""
	expect from p1:
		/store-done (blake2#[0-9a-f]*)/ capture r4

	let tid1 = "00000000-0000-0000-0000-000000000001"
	let tid2 = "00000000-0000-0000-0000-000000000002"

	# Watch head from multiple processes

	send "head-create $tid1 $r1" to p1
	expect /head-create-done $tid1 ([0-9a-f-]+)/ from p1 capture hid1

	send "head-watch $tid1 $hid1" to p1
	send "head-watch $tid1 $hid1" to p2

	expect /head-watch-done $tid1 $hid1 ([0-9]+)/ from p1 capture w1_1
	expect /head-watch-done $tid1 $hid1 ([0-9]+)/ from p2 capture w2_1

	local:
		expect /head-watch-cb $w1_1 (blake2#[0-9a-f]+)/ from p1 capture new
		guard (new == r1)

	local:
		expect /head-watch-cb $w2_1 (blake2#[0-9a-f]+)/ from p2 capture new
		guard (new == r1)

	send "head-replace $tid1 $hid1 $r2 $r1" to p1
	expect /head-replace-fail $tid1 $hid1 $r2 $r1 $r1/ from p1

	send "head-replace $tid1 $hid1 $r1 $r2" to p1
	expect /head-replace-done $tid1 $hid1 $r1 $r2/ from p1

	local:
		expect /head-watch-cb $w1_1 (blake2#[0-9a-f]+)/ from p1 capture new
		guard (new == r2)

	local:
		expect /head-watch-cb $w2_1 (blake2#[0-9a-f]+)/ from p2 capture new
		guard (new == r2)

	# Watch distinct heads and head types

	send "head-create $tid1 $r1" to p1
	expect /head-create-done $tid1 ([0-9a-f-]+)/ from p1 capture hid1_2

	send "head-create $tid2 $r2" to p1
	expect /head-create-done $tid2 ([0-9a-f-]+)/ from p1 capture hid2

	send "head-watch $tid1 $hid1_2" to p1
	send "head-watch $tid1 $hid1_2" to p2
	send "head-watch $tid2 $hid2" to p1
	send "head-watch $tid2 $hid2" to p2

	expect /head-watch-done $tid1 $hid1_2 ([0-9]+)/ from p1 capture w1_1_2
	expect /head-watch-done $tid1 $hid1_2 ([0-9]+)/ from p2 capture w2_1_2
	expect /head-watch-done $tid2 $hid2 ([0-9]+)/ from p1 capture w1_2
	expect /head-watch-done $tid2 $hid2 ([0-9]+)/ from p2 capture w2_2

	local:
		expect /head-watch-cb $w1_1_2 (blake2#[0-9a-f]+)/ from p1 capture new
		guard (new == r1)

	local:
		expect /head-watch-cb $w2_1_2 (blake2#[0-9a-f]+)/ from p2 capture new
		guard (new == r1)

	local:
		expect /head-watch-cb $w1_2 (blake2#[0-9a-f]+)/ from p1 capture new
		guard (new == r2)

	local:
		expect /head-watch-cb $w2_2 (blake2#[0-9a-f]+)/ from p2 capture new
		guard (new == r2)

	send "head-replace $tid1 $hid1_2 $r1 $r2" to p1
	expect /head-replace-done $tid1 $hid1_2 $r1 $r2/ from p1

	local:
		expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p1 capture w, new
		guard (w == w1_1_2)
		guard (new == r2)

	local:
		expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p2 capture w, new
		guard (w == w2_1_2)
		guard (new == r2)

	send "head-replace $tid2 $hid2 $r2 $r3" to p1
	expect /head-replace-done $tid2 $hid2 $r2 $r3/ from p1

	local:
		expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p1 capture w, new
		guard (w == w1_2)
		guard (new == r3)

	local:
		expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p2 capture w, new
		guard (w == w2_2)
		guard (new == r3)

	# Unwatch head

	send "head-unwatch $w1_1_2" to p1
	expect /head-unwatch-done $w1_1_2/ from p1

	send "head-unwatch $w1_2" to p1
	expect /head-unwatch-done $w1_2/ from p1

	send "head-replace $tid2 $hid2 $r3 $r4" to p1
	expect /head-replace-done $tid2 $hid2 $r3 $r4/ from p1

	send "head-replace $tid1 $hid1_2 $r2 $r1" to p1
	expect /head-replace-done $tid1 $hid1_2 $r2 $r1/ from p1

	send "head-replace $tid1 $hid1 $r2 $r3" to p1
	expect /head-replace-done $tid1 $hid1 $r2 $r3/ from p1

	local:
		expect /head-watch-cb $w2_2 (blake2#[0-9a-f]+)/ from p2 capture new
		guard (new == r4)

	local:
		expect /head-watch-cb $w2_1_2 (blake2#[0-9a-f]+)/ from p2 capture new
		guard (new == r1)

	local:
		expect /head-watch-cb $w2_1 (blake2#[0-9a-f]+)/ from p2 capture new
		guard (new == r3)

	local:
		expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p1 capture w, new
		guard (w == w1_1)
		guard (new == r3)

	# Multiple watchers on the same head

	send "head-watch $tid1 $hid1" to p1
	expect /head-watch-done $tid1 $hid1 ([0-9]+)/ from p1 capture w1_1b

	local:
		expect /head-watch-cb $w1_1b (blake2#[0-9a-f]+)/ from p1 capture new
		guard (new == r3)

	send "head-watch $tid1 $hid1" to p1
	expect /head-watch-done $tid1 $hid1 ([0-9]+)/ from p1 capture w1_1c

	local:
		expect /head-watch-cb $w1_1c (blake2#[0-9a-f]+)/ from p1 capture new
		guard (new == r3)

	send "head-replace $tid1 $hid1 $r3 $r4" to p1
	expect /head-replace-done $tid1 $hid1 $r3 $r4/ from p1

	local:
		expect /head-watch-cb $w1_1 (blake2#[0-9a-f]+)/ from p1 capture new
		guard (new == r4)

	local:
		expect /head-watch-cb $w1_1b (blake2#[0-9a-f]+)/ from p1 capture new
		guard (new == r4)

	local:
		expect /head-watch-cb $w1_1c (blake2#[0-9a-f]+)/ from p1 capture new
		guard (new == r4)

	local:
		expect /head-watch-cb $w2_1 (blake2#[0-9a-f]+)/ from p2 capture new
		guard (new == r4)

	for w in [ w1_1, w1_1c ]:
		send "head-unwatch $w" to p1
		expect /head-unwatch-done $w/ from p1

	send "head-replace $tid1 $hid1 $r4 $r1" to p1
	expect /head-replace-done $tid1 $hid1 $r4 $r1/ from p1

	send "head-replace $tid1 $hid1 $r1 $r2" to p1
	expect /head-replace-done $tid1 $hid1 $r1 $r2/ from p1

	local:
		expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p2 capture w, new
		guard (w == w2_1)
		guard (new == r1)

	local:
		expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p2 capture w, new
		guard (w == w2_1)
		guard (new == r2)

	local:
		expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p1 capture w, new
		guard (w == w1_1b)
		guard (new == r1)

	local:
		expect /head-watch-cb ([0-9]+) (blake2#[0-9a-f]+)/ from p1 capture w, new
		guard (w == w1_1b)
		guard (new == r2)


test SharedStateWatcher:
	spawn as p1
	spawn as p2
	send "create-identity Device1 Owner" to p1
	send "create-identity Device2" to p2
	send "watch-local-identity" to p1
	send "watch-local-identity" to p2
	send "start-server" to p1
	send "start-server" to p2
	expect from p1:
		/local-identity Device1 Owner/
		/peer 1 addr ${p2.node.ip} 29665/
		/peer 1 id Device2/
	expect from p2:
		/local-identity Device2/
		/peer 1 addr ${p1.node.ip} 29665/
		/peer 1 id Device1 Owner/

	local:
		send "attach-to 1" to p2
		expect /attach-request 1 ([0-9]*)/ from p1 capture code1
		expect /attach-response 1 ([0-9]*)/ from p2 capture code2
		guard (code1 == code2)

	send "attach-accept 1" to p1
	send "attach-accept 1" to p2
	expect /attach-request-done 1/ from p1
	expect /attach-response-done 1/ from p2
	expect /local-identity Device2 Owner/ from p2
	expect /peer 1 id Device2 Owner/ from p1

	for i in [1..5]:
		send "update-local-identity Owner2" to p1
		send "shared-state-get" to p1
		expect /shared-state-get (.*)/ from p1 capture s1

		send "shared-state-wait $s1" to p2
		expect /shared-state-wait $s1/ from p2

		send "update-local-identity Owner1" to p1
		send "shared-state-get" to p1
		expect /shared-state-get (.*)/ from p1 capture s2

		send "shared-state-wait $s1" to p2
		send "shared-state-wait $s2" to p2
		expect /shared-state-wait $s1/ from p2
		expect /shared-state-wait $s2/ from p2