Compare commits

...

2 Commits

Author SHA1 Message Date
Emery Hemingway 5f45f76452 Add solo5 tests 2024-04-03 11:01:17 +01:00
Emery Hemingway 403e54878c Rename syndicate/actors to syndicate/drivers 2024-04-03 11:01:02 +01:00
9 changed files with 75 additions and 6 deletions

View File

@ -127,10 +127,10 @@
"taps"
],
"path": "/nix/store/n86g5fw60z1k53bn35zvrwlwmyk3ixdn-source",
"rev": "756cb07b4f874181ad34c370cad6082ee65f646d",
"rev": "6ec1491c178bd37491ca55c012675bd525391e29",
"sha256": "0dp7ml3kj2fi6isvjkkxf02hwj0gshx6qra0ghnk2cbfykbcgfp8",
"srcDir": "src",
"url": "https://git.sr.ht/~ehmry/nim_taps/archive/756cb07b4f874181ad34c370cad6082ee65f646d.tar.gz"
"url": "https://git.sr.ht/~ehmry/nim_taps/archive/6ec1491c178bd37491ca55c012675bd525391e29.tar.gz"
},
{
"date": "2024-04-02T15:38:57+01:00",

View File

@ -127,7 +127,7 @@ else:
discard close(fd)
driver.timers.excl(fd)
proc spawnTimerActor*(turn: var Turn; ds: Cap): Actor {.discardable.} =
proc spawnTimerDriver*(turn: var Turn; ds: Cap): Actor {.discardable.} =
## Spawn a timer actor that responds to
## dataspace observations of timeouts on `ds`.
linkActor(turn, "timers") do (turn: var Turn):

View File

@ -1,6 +1,6 @@
# Package
version = "20240402"
version = "20240403"
author = "Emery Hemingway"
description = "Syndicated actors for conversational concurrency"
license = "Unlicense"

View File

@ -0,0 +1,39 @@
# SPDX-FileCopyrightText: ☭ Emery Hemingway
# SPDX-License-Identifier: Unlicense
import taps
import solo5
import syndicate, syndicate/relays
import preserves
acquireDevices([("relay", netBasic)], netAcquireHook)
type Netif {.preservesRecord: "netif"} = object
device, ipAddr: string
proc spawnNetifActor(turn: var Turn; ds: Cap) =
spawnActor(turn, "netif") do (turn: var Turn):
let facet = turn.facet
onInterfaceUp do (device: string; ip: IpAddress):
run(facet) do (turn: var Turn):
if not ip.isLinkLocal:
discard publish(turn, ds, Netif(device: device, ipAddr: $ip))
runActor("relay-test") do (turn: var Turn):
let root = turn.facet
onStop(turn) do (turn: var Turn):
quit()
let ds = newDataspace(turn)
spawnNetifActor(turn, ds)
spawnRelays(turn, ds)
var
route: Route
pr = parsePreserves $solo5_start_info.cmdline
if route.fromPreserves pr:
echo "parsed route ", route.toPreserves
during(turn, ds, Netif?:{1: grab()}) do (ip: string):
echo "Acquired address ", ip
resolve(turn, ds, route) do (turn: var Turn; ds: Cap):
echo "route resolved!"
echo "stopping root facet"
stop(turn, root)

View File

@ -0,0 +1,3 @@
define:ipv6Enabled
define:traceSyndicate
import:"std/assertions"

25
tests/solo5_test.nim Normal file
View File

@ -0,0 +1,25 @@
# SPDX-FileCopyrightText: ☭ Emery Hemingway
# SPDX-License-Identifier: Unlicense
import std/times
import solo5
import syndicate, syndicate/drivers/timers
acquireDevices()
runActor("timer-test") do (turn: var Turn):
let timers = newDataspace(turn)
spawnTimerDriver(turn, timers)
onPublish(turn, timers, ?LaterThan(seconds: 1356100000)):
echo "now in 13th bʼakʼtun"
after(turn, timers, initDuration(seconds = 3)) do (turn: var Turn):
echo "third timer expired"
stopActor(turn)
after(turn, timers, initDuration(seconds = 1)) do (turn: var Turn):
echo "first timer expired"
after(turn, timers, initDuration(seconds = 2)) do (turn: var Turn):
echo "second timer expired"

2
tests/solo5_test.nim.cfg Normal file
View File

@ -0,0 +1,2 @@
define:ipv6Enabled
import:"std/assertions"

View File

@ -2,11 +2,11 @@
# SPDX-License-Identifier: Unlicense
import std/times
import syndicate, syndicate/actors/timers
import syndicate, syndicate/drivers/timers
runActor("timer-test") do (turn: var Turn):
let timers = newDataspace(turn)
spawnTimerActor(turn, timers)
spawnTimerDriver(turn, timers)
onPublish(turn, timers, ?LaterThan(seconds: 1356100000)):
echo "now in 13th bʼakʼtun"