Fix gcsafety issues in the test suite

This commit is contained in:
Zahary Karadjov 2020-03-24 19:42:15 +02:00 committed by zah
parent 86a3bea1ec
commit 22876da593
3 changed files with 9 additions and 9 deletions

View File

@ -30,8 +30,8 @@ type
slots*: seq[PeerSlot[A, B]]
man: SyncManager[A, B]
GetLocalHeadSlotCallback* = proc(): Slot
UpdateLocalBlocksCallback* = proc(list: openarray[SignedBeaconBlock]): bool
GetLocalHeadSlotCallback* = proc(): Slot {.gcsafe.}
UpdateLocalBlocksCallback* = proc(list: openarray[SignedBeaconBlock]): bool {.gcsafe.}
SyncManager*[A, B] = ref object
groups*: seq[PeerGroup[A, B]]
@ -128,7 +128,7 @@ proc updateLastSlot*(sq: SyncQueue, last: Slot) {.inline.} =
sq.lastSlot = last
proc push*(sq: SyncQueue, sr: SyncRequest,
data: seq[SignedBeaconBlock]) {.async.} =
data: seq[SignedBeaconBlock]) {.async, gcsafe.} =
## Push successfull result to queue ``sq``.
while true:
if (sq.queueSize > 0) and (sr.slot >= sq.outSlot + uint64(sq.queueSize)):
@ -888,7 +888,7 @@ proc updateStatus*[A, B](sman: SyncManager[A, B]) {.async.} =
pending[i].cancel()
raise exc
proc synchronize*[A, B](sman: SyncManager[A, B]) {.async.} =
proc synchronize*[A, B](sman: SyncManager[A, B]) {.async, gcsafe.} =
## TODO: This synchronization procedure is not optimal, we can do it better
## if spawn N parallel tasks, where N is number of peer groups.
var

View File

@ -193,14 +193,14 @@ suiteReport "PeerPool testing suite":
itemFut23.finished == false
itemFut24.finished == false
timedTest "Acquire/Sorting and consistency test":
timedTest "Acquire/Sorting and consistency test": closureScope:
const
TestsCount = 1000
MaxNumber = 1_000_000
var pool = newPeerPool[PeerTest, PeerTestID]()
proc testAcquireRelease(): Future[int] {.async.} =
proc testAcquireRelease(): Future[int] {.async, gcsafe.} =
var weight: int
var incoming, outgoing, total: seq[PeerTest]
var incWeight1, outWeight1, totWeight1: int
@ -362,7 +362,7 @@ suiteReport "PeerPool testing suite":
check waitFor(testPeerLifetime()) == true
timedTest "Safe/Clear test":
timedTest "Safe/Clear test": closureScope:
var pool = newPeerPool[PeerTest, PeerTestID]()
var peer1 = PeerTest.init("peer1", 10)
var peer2 = PeerTest.init("peer2", 9)
@ -409,7 +409,7 @@ suiteReport "PeerPool testing suite":
asyncCheck testConsumer()
check waitFor(testClose()) == true
timedTest "Access peers by key test":
timedTest "Access peers by key test": closureScope:
var pool = newPeerPool[PeerTest, PeerTestID]()
var peer1 = PeerTest.init("peer1", 10)
var peer2 = PeerTest.init("peer2", 9)

View File

@ -603,7 +603,7 @@ proc checkRequest(peer: SimplePeer, index: int, slot, count, step: int,
data: varargs[int]): bool {.inline.} =
result = checkRequest(peer.requests[index], slot, count, step, data)
proc syncManagerOnePeerTest(): Future[bool] {.async.} =
proc syncManagerOnePeerTest(): Future[bool] {.async, gcsafe.} =
# Syncing with one peer only.
var pool = newPeerPool[SimplePeer, SimplePeerKey]()
var peer = SimplePeer.init("id1")