986
|
1 import std/os
|
|
2
|
|
3 import semicongine
|
|
4
|
|
5 proc testSimple(storage: StorageType) =
|
|
6 const TEST_VALUE = 42
|
|
7 const KEY = "test"
|
|
8
|
|
9 # get default
|
|
10 var promise1 = load[int](storage, KEY)
|
|
11 assert promise1.awaitResult() == default(type(TEST_VALUE))
|
|
12
|
|
13 # save and load custom
|
|
14 var promise2 = store(storage, KEY, TEST_VALUE)
|
|
15 promise2.awaitStored()
|
|
16 promise1 = load[int](storage, KEY)
|
|
17 assert promise1.awaitResult() == TEST_VALUE
|
|
18
|
|
19 proc testBusyWait(storage: StorageType) =
|
|
20 const TEST_VALUE = "43"
|
|
21 const KEY = "test2"
|
|
22
|
|
23 # get default
|
|
24 var promise1 = load[string](storage, KEY)
|
|
25 while not promise1.hasResult():
|
|
26 sleep(1)
|
|
27 assert promise1.getResult() == default(type(TEST_VALUE))
|
|
28
|
|
29 # save and load custom
|
|
30 var promise2 = store(storage, KEY, TEST_VALUE)
|
|
31 while not promise2.isStored():
|
|
32 sleep(1)
|
|
33 promise1 = load[string](storage, KEY)
|
|
34 while not promise1.hasResult():
|
|
35 sleep(1)
|
|
36 assert promise1.awaitResult() == TEST_VALUE
|
|
37
|
|
38 proc main() =
|
|
39 echo "SystemStorage: Testing simple store/load"
|
|
40 SystemStorage.testSimple()
|
|
41 echo "SystemStorage: Testing store/load with busy wait"
|
|
42 SystemStorage.testBusyWait()
|
|
43
|
|
44 UserStorage.purge()
|
|
45 echo "UserStorage: Testing simple store/load"
|
|
46 UserStorage.testSimple()
|
|
47 echo "UserStorage: Testing store/load with busy wait"
|
|
48 UserStorage.testBusyWait()
|
|
49 UserStorage.purge()
|
|
50
|
|
51 when isMainModule:
|
|
52 main()
|