Merge branch 'fix_actors'
This commit is contained in:
6
tests/actor_clock.ce
Normal file
6
tests/actor_clock.ce
Normal 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()
|
||||
})
|
||||
9
tests/actor_connection.ce
Normal file
9
tests/actor_connection.ce
Normal 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
8
tests/actor_couple.ce
Normal 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')
|
||||
10
tests/actor_delay_cancel.ce
Normal file
10
tests/actor_delay_cancel.ce
Normal 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)
|
||||
5
tests/actor_helper_echo.ce
Normal file
5
tests/actor_helper_echo.ce
Normal 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)
|
||||
5
tests/actor_helper_report.ce
Normal file
5
tests/actor_helper_report.ce
Normal 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)
|
||||
2
tests/actor_helper_stop.ce
Normal file
2
tests/actor_helper_stop.ce
Normal 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
9
tests/actor_overling.ce
Normal 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
6
tests/actor_receiver.ce
Normal 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
30
tests/actor_requestors.ce
Normal 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
5
tests/actor_self.ce
Normal 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()
|
||||
9
tests/actor_send_reply.ce
Normal file
9
tests/actor_send_reply.ce
Normal 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
13
tests/actor_start.ce
Normal 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
10
tests/actor_time_limit.ce
Normal 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
2
tests/actor_unneeded.ce
Normal file
@@ -0,0 +1,2 @@
|
||||
// Test: $unneeded fires after the specified time
|
||||
$unneeded($stop, 1)
|
||||
@@ -163,3 +163,4 @@ if (failed > 0) {
|
||||
print(" FAIL " + error_names[_j] + ": " + error_reasons[_j])
|
||||
}
|
||||
}
|
||||
$stop()
|
||||
|
||||
@@ -37,3 +37,4 @@ function test_nested() {
|
||||
test_nested()
|
||||
|
||||
print("done")
|
||||
$stop()
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
// tests/reply_actor.ce - Simple child that just logs
|
||||
log.console("reply_actor: alive!")
|
||||
$stop()
|
||||
|
||||
Reference in New Issue
Block a user