fix: repostore started flag in stop() (#374)

This commit is contained in:
Eric Mastro 2023-03-17 02:00:36 +11:00 committed by GitHub
parent 086b5c3914
commit c9a62de13f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 2 deletions

View File

@ -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,

View File

@ -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