implements dhtEnable flag

This commit is contained in:
thatben 2025-03-10 14:09:41 +01:00
parent 1704d3dc30
commit 5bd35720b5
No known key found for this signature in database
GPG Key ID: 62C543548433D43E
3 changed files with 19 additions and 2 deletions

View File

@ -52,7 +52,8 @@ method start*(c: Crawler): Future[?!void] {.async.} =
proc onStep(): Future[?!void] {.async: (raises: []), gcsafe.} =
await c.step()
await c.state.whileRunning(onStep, c.state.config.stepDelayMs.milliseconds)
if c.state.config.dhtEnable:
await c.state.whileRunning(onStep, c.state.config.stepDelayMs.milliseconds)
return success()

View File

@ -55,6 +55,20 @@ suite "Crawler":
check:
!(dht.getNeighborsArg) == nid1
test "onStep is not activated when config.dhtEnable is false":
# Recreate crawler, reset mockstate:
(await crawler.stop()).tryGet()
state.steppers = @[]
# disable DHT:
state.config.dhtEnable = false
(await crawler.start()).tryGet()
todo.popReturn = success(nid1)
dht.getNeighborsReturn = success(responsive(nid1))
check:
state.steppers.len == 0
test "nodes returned by getNeighbors are raised as nodesFound":
var nodesFound = newSeq[Nid]()
proc onNodesFound(nids: seq[Nid]): Future[?!void] {.async.} =

View File

@ -22,7 +22,9 @@ method whileRunning*(s: MockState, step: OnStep, delay: Duration) {.async.} =
proc createMockState*(): MockState =
MockState(
status: ApplicationStatus.Running,
config: Config(),
config: Config(
dhtEnable: true
),
events: Events(
nodesFound: newAsyncDataEvent[seq[Nid]](),
newNodesDiscovered: newAsyncDataEvent[seq[Nid]](),