comparison tests/test_storage.nim @ 1097:bc3efccc2bf4

tmp: move stuff to notebook
author sam <sam@basx.dev>
date Sun, 07 Apr 2024 20:12:52 +0700
parents 9809bd9e2cdb
children 3e0116b5d2ed
comparison
equal deleted inserted replaced
1096:9809bd9e2cdb 1097:bc3efccc2bf4
1 import std/os 1 import std/os
2 import std/strformat 2 import std/strformat
3 3
4 import semicongine 4 import semicongine
5 5
6 #[
6 proc testSimple(storage: StorageType) = 7 proc testSimple(storage: StorageType) =
7 const TEST_VALUE = 42 8 const TEST_VALUE = 42
8 const KEY = "test" 9 const KEY = "test"
9 10
10 # get default 11 # get default
41 let key = &"key-{i}" 42 let key = &"key-{i}"
42 var p = store(storage, key, i) 43 var p = store(storage, key, i)
43 p.awaitStored() 44 p.awaitStored()
44 var p1 = load[int](storage, key) 45 var p1 = load[int](storage, key)
45 assert p1.awaitResult() == i 46 assert p1.awaitResult() == i
47 ]#
46 48
47 proc concurrentStressTest(storage: StorageType) = 49 proc concurrentStressTest(storage: StorageType) =
48 var storeFutures: seq[StoreFuture[int]] 50 var storeFutures: seq[StoreFuture[int]]
49 51
50 for i in 1 .. 10000: 52 for i in 1 .. 10000:
51 let key = &"key-{i}" 53 let key = &"key-{i}"
52 echo key 54 echo key
53 storeFutures.add store(storage, key, i) 55 store()
56 # storeFutures.add store(storage, key, i)
54 57
55 for i in 1 .. 10000: 58 for i in 1 .. 10000:
56 echo i 59 echo i
57 let key = &"key-{i}" 60 let key = &"key-{i}"
58 storeFutures[i - 1].awaitStored() 61 storeFutures[i - 1].awaitStored()
59 var p1 = load[int](storage, key) 62 var p1 = load[int](storage, key)
60 assert p1.awaitResult() == i 63 assert p1.awaitResult() == i
61 64
65 #[
62 proc main() = 66 proc main() =
63 SystemStorage.purge() 67 SystemStorage.purge()
64 echo "SystemStorage: Testing simple store/load" 68 echo "SystemStorage: Testing simple store/load"
65 SystemStorage.testSimple() 69 SystemStorage.testSimple()
66 echo "SystemStorage: Testing store/load with busy wait" 70 echo "SystemStorage: Testing store/load with busy wait"
79 UserStorage.purge() 83 UserStorage.purge()
80 84
81 # TODO: fails currently, but is likely not too important 85 # TODO: fails currently, but is likely not too important
82 # echo "Stress test with 10'000 saves/loads and a little concurrency" 86 # echo "Stress test with 10'000 saves/loads and a little concurrency"
83 # SystemStorage.concurrentStressTest() 87 # SystemStorage.concurrentStressTest()
88 ]#
84 89
85 when isMainModule: 90 when isMainModule:
86 main() 91 echo "Stress test with 10'000 saves/loads and a little concurrency"
92 SystemStorage.concurrentStressTest()
93 # main()