diff --git a/codex/stores/repostore.nim b/codex/stores/repostore.nim index 4511546c..6a804276 100644 --- a/codex/stores/repostore.nim +++ b/codex/stores/repostore.nim @@ -371,8 +371,7 @@ proc start*(self: RepoStore): Future[void] {.async.} = proc stop*(self: RepoStore): Future[void] {.async.} = ## Stop repo ## - - if self.started: + if not self.started: trace "Repo is not started" return @@ -380,6 +379,8 @@ proc stop*(self: RepoStore): Future[void] {.async.} = (await self.repoDs.close()).expect("Should close repo store!") (await self.metaDs.close()).expect("Should close meta store!") + self.started = false + func new*( T: type RepoStore, repoDs: Datastore, diff --git a/tests/codex/stores/testrepostore.nim b/tests/codex/stores/testrepostore.nim index 30f0fb0d..42697499 100644 --- a/tests/codex/stores/testrepostore.nim +++ b/tests/codex/stores/testrepostore.nim @@ -22,6 +22,39 @@ import ../helpers import ../helpers/mockclock import ./commonstoretests +suite "Test RepoStore start/stop": + + var + repoDs: Datastore + metaDs: Datastore + + setup: + repoDs = SQLiteDatastore.new(Memory).tryGet() + metaDs = SQLiteDatastore.new(Memory).tryGet() + + test "Should set started flag once started": + let repo = RepoStore.new(repoDs, metaDs, quotaMaxBytes = 200) + await repo.start() + check repo.started + + test "Should set started flag to false once stopped": + let repo = RepoStore.new(repoDs, metaDs, quotaMaxBytes = 200) + await repo.start() + await repo.stop() + check not repo.started + + test "Should allow start to be called multiple times": + let repo = RepoStore.new(repoDs, metaDs, quotaMaxBytes = 200) + await repo.start() + await repo.start() + check repo.started + + test "Should allow stop to be called multiple times": + let repo = RepoStore.new(repoDs, metaDs, quotaMaxBytes = 200) + await repo.stop() + await repo.stop() + check not repo.started + suite "RepoStore": var repoDs: Datastore