@@ -2,120 +2,11 @@ package actor
22
33import (
44 "context"
5- "errors"
65 "sync"
7- "sync/atomic"
86 "testing"
97 "time"
108)
119
12- // TestMessage is a simple test message type
13- type TestMessage struct {
14- ID string
15- Content string
16- }
17-
18- func (m * TestMessage ) Type () string {
19- return "test"
20- }
21-
22- // CounterMessage is used for counting operations
23- type CounterMessage struct {}
24-
25- func (m * CounterMessage ) Type () string {
26- return "counter"
27- }
28-
29- // ErrorMessage is used to trigger errors
30- type ErrorMessage struct {}
31-
32- func (m * ErrorMessage ) Type () string {
33- return "error"
34- }
35-
36- // TestActor is a simple actor implementation for testing
37- type TestActor struct {
38- id string
39- receivedMsgs []Message
40- receiveCount atomic.Int32
41- startCalled atomic.Bool
42- stopCalled atomic.Bool
43- shouldError atomic.Bool
44- mu sync.Mutex
45- receiveHandler func (ctx context.Context , msg Message ) error
46- }
47-
48- func NewTestActor (id string ) * TestActor {
49- return & TestActor {
50- id : id ,
51- receivedMsgs : make ([]Message , 0 ),
52- }
53- }
54-
55- func (a * TestActor ) ID () string {
56- return a .id
57- }
58-
59- func (a * TestActor ) Start (ctx context.Context ) error {
60- a .startCalled .Store (true )
61- return nil
62- }
63-
64- func (a * TestActor ) Stop (ctx context.Context ) error {
65- a .stopCalled .Store (true )
66- return nil
67- }
68-
69- func (a * TestActor ) Receive (ctx context.Context , msg Message ) error {
70- a .receiveCount .Add (1 )
71-
72- if a .receiveHandler != nil {
73- return a .receiveHandler (ctx , msg )
74- }
75-
76- a .mu .Lock ()
77- a .receivedMsgs = append (a .receivedMsgs , msg )
78- a .mu .Unlock ()
79-
80- if a .shouldError .Load () {
81- return errors .New ("test error" )
82- }
83-
84- if _ , ok := msg .(* ErrorMessage ); ok {
85- return errors .New ("error message received" )
86- }
87-
88- return nil
89- }
90-
91- func (a * TestActor ) GetReceivedMessages () []Message {
92- a .mu .Lock ()
93- defer a .mu .Unlock ()
94- msgs := make ([]Message , len (a .receivedMsgs ))
95- copy (msgs , a .receivedMsgs )
96- return msgs
97- }
98-
99- func (a * TestActor ) GetReceiveCount () int32 {
100- return a .receiveCount .Load ()
101- }
102-
103- func (a * TestActor ) WasStartCalled () bool {
104- return a .startCalled .Load ()
105- }
106-
107- func (a * TestActor ) WasStopCalled () bool {
108- return a .stopCalled .Load ()
109- }
110-
111- func (a * TestActor ) SetShouldError (val bool ) {
112- a .shouldError .Store (val )
113- }
114-
115- func (a * TestActor ) SetReceiveHandler (handler func (ctx context.Context , msg Message ) error ) {
116- a .receiveHandler = handler
117- }
118-
11910// TestNewActorRef tests creating a new actor reference
12011func TestNewActorRef (t * testing.T ) {
12112 actor := NewTestActor ("test-1" )
@@ -335,7 +226,7 @@ func TestActorRefReceiveError(t *testing.T) {
335226 }
336227}
337228
338- func TestActorRefSequentialProcessing (t * testing.T ) {
229+ func TestActorRefSequentialProcessing_Variants (t * testing.T ) {
339230 ctx := context .Background ()
340231 actor := NewTestActor ("test-1" )
341232 ref := NewActorRef ("test-1" , actor , 10 , WithSequentialProcessing ())
@@ -367,7 +258,7 @@ func TestActorRefSequentialProcessing(t *testing.T) {
367258}
368259
369260// TestActorRefContextCancellation tests context cancellation during message processing
370- func TestActorRefContextCancellation (t * testing.T ) {
261+ func TestActorRefContextCancellation_Basic (t * testing.T ) {
371262 ctx , cancel := context .WithCancel (context .Background ())
372263 actor := NewTestActor ("test-1" )
373264
@@ -414,7 +305,7 @@ func TestActorRefContextCancellation(t *testing.T) {
414305}
415306
416307// TestSystemSpawn tests spawning actors in the system
417- func TestSystemSpawn (t * testing.T ) {
308+ func TestSystemSpawn_Basic (t * testing.T ) {
418309 ctx := context .Background ()
419310 system := NewSystem ()
420311
@@ -446,7 +337,7 @@ func TestSystemSpawn(t *testing.T) {
446337}
447338
448339// TestSystemGet tests retrieving actors from the system
449- func TestSystemGet (t * testing.T ) {
340+ func TestSystemGet_Basic (t * testing.T ) {
450341 ctx := context .Background ()
451342 system := NewSystem ()
452343
@@ -479,7 +370,7 @@ func TestSystemGet(t *testing.T) {
479370}
480371
481372// TestSystemStop tests stopping individual actors
482- func TestSystemStop (t * testing.T ) {
373+ func TestSystemStop_Basic (t * testing.T ) {
483374 ctx := context .Background ()
484375 system := NewSystem ()
485376
@@ -516,7 +407,7 @@ func TestSystemStop(t *testing.T) {
516407}
517408
518409// TestSystemStopAll tests stopping all actors
519- func TestSystemStopAll (t * testing.T ) {
410+ func TestSystemStopAll_Basic (t * testing.T ) {
520411 ctx := context .Background ()
521412 system := NewSystem ()
522413
@@ -560,7 +451,7 @@ func TestSystemStopAll(t *testing.T) {
560451}
561452
562453// TestSystemConcurrentAccess tests concurrent access to the system
563- func TestSystemConcurrentAccess (t * testing.T ) {
454+ func TestSystemConcurrentAccess_Basic (t * testing.T ) {
564455 ctx := context .Background ()
565456 system := NewSystem ()
566457
@@ -597,7 +488,7 @@ func TestSystemConcurrentAccess(t *testing.T) {
597488}
598489
599490// TestActorCommunication tests communication between actors
600- func TestActorCommunication (t * testing.T ) {
491+ func TestActorCommunication_Basic (t * testing.T ) {
601492 ctx := context .Background ()
602493 system := NewSystem ()
603494
@@ -648,7 +539,7 @@ func TestActorCommunication(t *testing.T) {
648539}
649540
650541// BenchmarkActorSend benchmarks sending messages to an actor
651- func BenchmarkActorSend (b * testing.B ) {
542+ func BenchmarkActorSend_Basic (b * testing.B ) {
652543 ctx := context .Background ()
653544 actor := NewTestActor ("bench-actor" )
654545 ref := NewActorRef ("bench-actor" , actor , 10000 )
@@ -676,8 +567,7 @@ func BenchmarkActorSend(b *testing.B) {
676567 }
677568}
678569
679- // BenchmarkActorSpawn benchmarks spawning actors
680- func BenchmarkActorSpawn (b * testing.B ) {
570+ func BenchmarkActorSpawn_Basic (b * testing.B ) {
681571 ctx := context .Background ()
682572
683573 b .ResetTimer ()
0 commit comments