dactor_test 2.0.0
dactor_test: ^2.0.0 copied to clipboard
Test utilities for the Dactor actor system - TestActorSystem and TestProbe
example/dactor_test_example.dart
import 'package:dactor/dactor.dart';
import 'package:dactor_test/dactor_test.dart';
import 'package:test/test.dart';
class Echo extends Actor {
@override
Future<void> onMessage(dynamic message) async {
context.sender?.tell('echo: $message');
}
}
void main() {
late TestActorSystem system;
setUp(() => system = TestActorSystem());
tearDown(() => system.shutdown());
test('echoes to the sender', () async {
final probe = await system.createProbe();
final echo = await system.spawn('echo', () => Echo());
// The probe is the sender, so the reply comes back to it.
probe.send(echo, 'hello');
await probe.expectMsg('echo: hello', timeout: const Duration(seconds: 1));
});
}