diff tests/test_storage.nim @ 1098:45cf94a6535c

did: undo complicated background storage API, sync is good enough for now
author sam <sam@basx.dev>
date Sun, 07 Apr 2024 21:56:43 +0700
parents bc3efccc2bf4
children 1705e005cdee
line wrap: on
line diff
--- a/tests/test_storage.nim	Sun Apr 07 20:12:52 2024 +0700
+++ b/tests/test_storage.nim	Sun Apr 07 21:56:43 2024 +0700
@@ -3,78 +3,31 @@
 
 import semicongine
 
-#[
 proc testSimple(storage: StorageType) =
   const TEST_VALUE = 42
   const KEY = "test"
 
   # get default
-  var future1 = load[int](storage, KEY)
-  assert future1.awaitResult() == default(type(TEST_VALUE))
+  assert load[int](storage, KEY) == default(type(TEST_VALUE))
 
   # save and load custom
-  var future2 = store(storage, KEY, TEST_VALUE)
-  future2.awaitStored()
-  future1 = load[int](storage, KEY)
-  assert future1.awaitResult() == TEST_VALUE
-
-proc testBusyWait(storage: StorageType) =
-  const TEST_VALUE = "43"
-  const KEY = "test2"
-
-  # get default
-  var future1 = load[string](storage, KEY)
-  while not future1.hasResult():
-    sleep(1)
-  assert future1.getResult() == default(type(TEST_VALUE))
-
-  # save and load custom
-  var future2 = store(storage, KEY, TEST_VALUE)
-  while not future2.isStored():
-    sleep(1)
-  future1 = load[string](storage, KEY)
-  while not future1.hasResult():
-    sleep(1)
-  assert future1.awaitResult() == TEST_VALUE
+  store(storage, KEY, TEST_VALUE)
+  assert load[int](storage, KEY) == TEST_VALUE
 
 proc stressTest(storage: StorageType) =
   for i in 1 .. 10000:
     let key = &"key-{i}"
-    var p = store(storage, key, i)
-    p.awaitStored()
-    var p1 = load[int](storage, key)
-    assert p1.awaitResult() == i
-]#
-
-proc concurrentStressTest(storage: StorageType) =
-  var storeFutures: seq[StoreFuture[int]]
+    store(storage, key, i)
+    assert load[int](storage, key) == i
 
-  for i in 1 .. 10000:
-    let key = &"key-{i}"
-    echo key
-    store()
-    # storeFutures.add store(storage, key, i)
-
-  for i in 1 .. 10000:
-    echo i
-    let key = &"key-{i}"
-    storeFutures[i - 1].awaitStored()
-    var p1 = load[int](storage, key)
-    assert p1.awaitResult() == i
-
-#[
 proc main() =
   SystemStorage.purge()
   echo "SystemStorage: Testing simple store/load"
   SystemStorage.testSimple()
-  echo "SystemStorage: Testing store/load with busy wait"
-  SystemStorage.testBusyWait()
 
   UserStorage.purge()
   echo "UserStorage: Testing simple store/load"
   UserStorage.testSimple()
-  echo "UserStorage: Testing store/load with busy wait"
-  UserStorage.testBusyWait()
 
   echo "Stress test with 10'000 saves/loads"
   SystemStorage.stressTest()
@@ -82,12 +35,6 @@
   SystemStorage.purge()
   UserStorage.purge()
 
-  # TODO: fails currently, but is likely not too important
-  # echo "Stress test with 10'000 saves/loads and a little concurrency"
-  # SystemStorage.concurrentStressTest()
-]#
 
 when isMainModule:
-  echo "Stress test with 10'000 saves/loads and a little concurrency"
-  SystemStorage.concurrentStressTest()
-  # main()
+  main()