update actor doc and add more actor based tests

This commit is contained in:
2026-02-17 11:50:46 -06:00
parent 2d054fcf21
commit 2be2b15a61
21 changed files with 268 additions and 51 deletions

6
tests/actor_clock.ce Normal file
View File

@@ -0,0 +1,6 @@
// Test: $clock fires with a time number
$clock(function(t) {
if (!is_number(t)) disrupt
if (t <= 0) disrupt
$stop()
})

View File

@@ -0,0 +1,9 @@
// Test: $connection reports local for a child actor
$start(function(event) {
if (event.type == 'greet') {
$connection(function(info) {
if (info.type != "local") disrupt
$stop()
}, event.actor, {})
}
}, 'tests/actor_helper_echo')

8
tests/actor_couple.ce Normal file
View File

@@ -0,0 +1,8 @@
// Test: $couple($self) is a no-op, $couple on a child doesn't disrupt
$couple($self)
$start(function(event) {
if (event.type == 'greet') {
$couple(event.actor)
$delay($stop, 0.1)
}
}, 'tests/actor_helper_echo')

View File

@@ -0,0 +1,10 @@
// Test: $delay returns a cancel function that prevents the callback
var fired = false
var cancel = $delay(function() {
fired = true
}, 0.5)
cancel()
var _t = $delay(function() {
if (fired) disrupt
$stop()
}, 1)

View File

@@ -0,0 +1,5 @@
// Helper actor that echoes messages back with {pong: true}
$receiver(function(msg) {
send(msg, {pong: true})
})
var _t = $delay($stop, 5)

View File

@@ -0,0 +1,5 @@
// Helper actor that reports $overling status
$receiver(function(msg) {
send(msg, {has_overling: $overling != null})
})
var _t = $delay($stop, 5)

View File

@@ -0,0 +1,2 @@
// Helper actor that stops after 0.1 seconds
var _t = $delay($stop, 0.1)

9
tests/actor_overling.ce Normal file
View File

@@ -0,0 +1,9 @@
// Test: child actor reports $overling is not null
$start(function(event) {
if (event.type == 'greet') {
send(event.actor, {check: true}, function(reply) {
if (!reply.has_overling) disrupt
$stop()
})
}
}, 'tests/actor_helper_report')

6
tests/actor_receiver.ce Normal file
View File

@@ -0,0 +1,6 @@
// Test: $receiver fires when sending to self
$receiver(function(msg) {
if (!msg.test) disrupt
$stop()
})
send($self, {test: true})

30
tests/actor_requestors.ce Normal file
View File

@@ -0,0 +1,30 @@
// Test: sequence, parallel, and fallback requestor composition
var immediate = function(callback, value) {
callback(42)
}
var add_one = function(callback, value) {
callback(value + 1)
}
var broken = function(callback, value) {
callback(null, "broken")
}
var _t = sequence([immediate, add_one])(function(result, reason) {
if (reason != null) disrupt
if (result != 43) disrupt
parallel([immediate, immediate])(function(results, reason) {
if (reason != null) disrupt
if (length(results) != 2) disrupt
if (results[0] != 42) disrupt
if (results[1] != 42) disrupt
fallback([broken, immediate])(function(result, reason) {
if (reason != null) disrupt
if (result != 42) disrupt
$stop()
})
})
})

5
tests/actor_self.ce Normal file
View File

@@ -0,0 +1,5 @@
// Test: $self and is_actor
if ($self == null) disrupt
if (!is_actor($self)) disrupt
if (!is_stone($self)) disrupt
$stop()

View File

@@ -0,0 +1,9 @@
// Test: send with reply callback
$start(function(event) {
if (event.type == 'greet') {
send(event.actor, {ping: true}, function(reply) {
if (!reply.pong) disrupt
$stop()
})
}
}, 'tests/actor_helper_echo')

13
tests/actor_start.ce Normal file
View File

@@ -0,0 +1,13 @@
// Test: $start lifecycle events (greet and stop)
var got_greet = false
$start(function(event) {
if (event.type == 'greet') {
if (!event.actor) disrupt
if (!is_actor(event.actor)) disrupt
got_greet = true
}
if (event.type == 'stop') {
if (!got_greet) disrupt
$stop()
}
}, 'tests/actor_helper_stop')

10
tests/actor_time_limit.ce Normal file
View File

@@ -0,0 +1,10 @@
// Test: $time_limit fires timeout for a requestor that never completes
var never_complete = function(callback, value) {
return null
}
var timed = $time_limit(never_complete, 0.5)
var _t = timed(function(val, reason) {
if (val != null) disrupt
if (reason == null) disrupt
$stop()
})

2
tests/actor_unneeded.ce Normal file
View File

@@ -0,0 +1,2 @@
// Test: $unneeded fires after the specified time
$unneeded($stop, 1)

View File

@@ -163,3 +163,4 @@ if (failed > 0) {
print(" FAIL " + error_names[_j] + ": " + error_reasons[_j])
}
}
$stop()

View File

@@ -37,3 +37,4 @@ function test_nested() {
test_nested()
print("done")
$stop()

View File

@@ -8,7 +8,7 @@ $start(e => {
if (e.type == 'disrupt') {
log.console(`underling successfully killed.`)
send($parent, { type: "test_result", passed: true })
send($overling, {type: "test_result", passed: true})
$stop()
}
}, 'tests/hang_actor')

View File

@@ -1,2 +1,3 @@
// tests/reply_actor.ce - Simple child that just logs
log.console("reply_actor: alive!")
$stop()