Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mark readNext() as {.gcsafe.} in order to use w/ threaded mode #25

Merged
merged 1 commit into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions redis.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ task docs, "Build documentation":

task test, "Run tests":
exec "nim c -r tests/main.nim"
exec "nim c -r --threads:on tests/main.nim"
4 changes: 2 additions & 2 deletions src/redis.nim
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ proc readSingleString(r: Redis | AsyncRedis): Future[RedisString] {.multisync.}
result = res.get(redisNil)
finaliseCommand(r)

proc readNext(r: Redis): RedisList
proc readNext(r: AsyncRedis): Future[RedisList]
proc readNext(r: Redis): RedisList {.gcsafe.}
proc readNext(r: AsyncRedis): Future[RedisList] {.gcsafe.}
proc readArrayLines(r: Redis | AsyncRedis, countLine: string): Future[RedisList] {.multisync.} =
if countLine[0] != '*':
raiseInvalidReply(r, '*', countLine[0])
Expand Down
17 changes: 15 additions & 2 deletions tests/main.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import redis, unittest, asyncdispatch

suite "redis tests":
template syncTests() =
let r = redis.open("localhost")
let keys = r.keys("*")
doAssert keys.len == 0, "Don't want to mess up an existing DB."
Expand Down Expand Up @@ -100,6 +100,8 @@ suite "redis tests":
# delete all keys in the DB at the end of the tests
discard r.flushdb()
r.quit()
suite "redis tests":
syncTests()

suite "redis async tests":
let r = waitFor redis.openAsync("localhost")
Expand Down Expand Up @@ -152,4 +154,15 @@ suite "redis async tests":
waitFor main()

discard waitFor r.flushdb()
waitFor r.quit()
waitFor r.quit()


when compileOption("threads"):
proc threadFunc() {.thread.} =
suite "redis threaded tests":
syncTests()

var th: Thread[void]
createThread(th, threadFunc)
joinThread(th)