Skip to content

Commit

Permalink
fix: fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tochemey committed Sep 11, 2024
1 parent 7b5c56e commit 33d0f1b
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions actor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func TestActor(t *testing.T) {
err = actorSystem.Start(ctx)
require.NoError(t, err)

time.Sleep(time.Second)

// create the event store
eventStore := memory.NewEventsStore()
// create a persistence id
Expand All @@ -72,6 +74,8 @@ func TestActor(t *testing.T) {
err = eventStore.Connect(ctx)
require.NoError(t, err)

time.Sleep(time.Second)

// create an instance of events stream
eventStream := eventstream.New()

Expand All @@ -81,6 +85,8 @@ func TestActor(t *testing.T) {
pid, _ := actorSystem.Spawn(ctx, behavior.ID(), actor)
require.NotNil(t, pid)

time.Sleep(time.Second)

var command proto.Message

command = &testpb.CreateAccount{AccountBalance: 500.00}
Expand Down Expand Up @@ -138,6 +144,8 @@ func TestActor(t *testing.T) {
err = eventStore.Disconnect(ctx)
require.NoError(t, err)

time.Sleep(time.Second)

// close the stream
eventStream.Close()
// stop the actor system
Expand All @@ -159,6 +167,8 @@ func TestActor(t *testing.T) {
err = actorSystem.Start(ctx)
require.NoError(t, err)

time.Sleep(time.Second)

// create the event store
eventStore := memory.NewEventsStore()
// create a persistence id
Expand All @@ -170,6 +180,8 @@ func TestActor(t *testing.T) {
err = eventStore.Connect(ctx)
require.NoError(t, err)

time.Sleep(time.Second)

// create an instance of events stream
eventStream := eventstream.New()

Expand All @@ -179,6 +191,8 @@ func TestActor(t *testing.T) {
pid, _ := actorSystem.Spawn(ctx, behavior.ID(), persistentActor)
require.NotNil(t, pid)

time.Sleep(time.Second)

var command proto.Message

command = &testpb.CreateAccount{AccountBalance: 500.00}
Expand Down Expand Up @@ -225,6 +239,9 @@ func TestActor(t *testing.T) {
require.NoError(t, eventStore.Disconnect(ctx))
// close the stream
eventStream.Close()

time.Sleep(time.Second)

// stop the actor system
err = actorSystem.Stop(ctx)
assert.NoError(t, err)
Expand All @@ -244,6 +261,8 @@ func TestActor(t *testing.T) {
err = actorSystem.Start(ctx)
require.NoError(t, err)

time.Sleep(time.Second)

// create the event store
eventStore := memory.NewEventsStore()
// create a persistence id
Expand All @@ -264,6 +283,8 @@ func TestActor(t *testing.T) {
pid, _ := actorSystem.Spawn(ctx, behavior.ID(), persistentActor)
require.NotNil(t, pid)

time.Sleep(time.Second)

command := &testpb.TestSend{}
// send the command to the actor
reply, err := actors.Ask(ctx, pid, command, time.Second)
Expand Down Expand Up @@ -302,6 +323,8 @@ func TestActor(t *testing.T) {
err = actorSystem.Start(ctx)
require.NoError(t, err)

time.Sleep(time.Second)

// create the event store
var (
testDatabase = "testdb"
Expand All @@ -327,6 +350,8 @@ func TestActor(t *testing.T) {
eventStore := pgeventstore.NewEventsStore(config)
require.NoError(t, eventStore.Connect(ctx))

time.Sleep(time.Second)

// create a persistence id
persistenceID := uuid.NewString()
// create the persistence behavior
Expand All @@ -336,6 +361,8 @@ func TestActor(t *testing.T) {
err = eventStore.Connect(ctx)
require.NoError(t, err)

time.Sleep(time.Second)

// create an instance of event stream
eventStream := eventstream.New()

Expand All @@ -346,6 +373,8 @@ func TestActor(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, pid)

time.Sleep(time.Second)

var command proto.Message

command = &testpb.CreateAccount{AccountBalance: 500.00}
Expand Down Expand Up @@ -406,6 +435,8 @@ func TestActor(t *testing.T) {
pid, err = actorSystem.ReSpawn(ctx, behavior.ID())
require.NoError(t, err)

time.Sleep(time.Second)

// fetch the current state
command = &egopb.GetStateCommand{}
reply, err = actors.Ask(ctx, pid, command, time.Second)
Expand All @@ -431,6 +462,9 @@ func TestActor(t *testing.T) {
testContainer.Cleanup()
// close the stream
eventStream.Close()

time.Sleep(time.Second)

err = actorSystem.Stop(ctx)
assert.NoError(t, err)
})
Expand All @@ -449,6 +483,8 @@ func TestActor(t *testing.T) {
err = actorSystem.Start(ctx)
require.NoError(t, err)

time.Sleep(time.Second)

// create the event store
eventStore := memory.NewEventsStore()
// create a persistence id
Expand All @@ -460,6 +496,8 @@ func TestActor(t *testing.T) {
err = eventStore.Connect(ctx)
require.NoError(t, err)

time.Sleep(time.Second)

// create an instance of event stream
eventStream := eventstream.New()

Expand All @@ -469,6 +507,8 @@ func TestActor(t *testing.T) {
pid, _ := actorSystem.Spawn(ctx, behavior.ID(), actor)
require.NotNil(t, pid)

time.Sleep(time.Second)

var command proto.Message

command = &testpb.CreateAccount{AccountBalance: 500.00}
Expand Down Expand Up @@ -549,6 +589,9 @@ func TestActor(t *testing.T) {
assert.NoError(t, eventStore.Disconnect(ctx))
// close the stream
eventStream.Close()

time.Sleep(time.Second)

// stop the actor system
err = actorSystem.Stop(ctx)
assert.NoError(t, err)
Expand All @@ -567,6 +610,8 @@ func TestActor(t *testing.T) {
err = actorSystem.Start(ctx)
require.NoError(t, err)

time.Sleep(time.Second)

// create the event store
eventStore := memory.NewEventsStore()
// create a persistence id
Expand All @@ -578,6 +623,8 @@ func TestActor(t *testing.T) {
err = eventStore.Connect(ctx)
require.NoError(t, err)

time.Sleep(time.Second)

// create an instance of events stream
eventStream := eventstream.New()

Expand All @@ -587,6 +634,8 @@ func TestActor(t *testing.T) {
pid, _ := actorSystem.Spawn(ctx, behavior.ID(), actor)
require.NotNil(t, pid)

time.Sleep(time.Second)

// send the command to the actor
reply, err := actors.Ask(ctx, pid, &testpb.CreateAccount{AccountBalance: 500.00}, 5*time.Second)
require.NoError(t, err)
Expand Down Expand Up @@ -624,6 +673,8 @@ func TestActor(t *testing.T) {
// disconnect from the event store
require.NoError(t, eventStore.Disconnect(ctx))

time.Sleep(time.Second)

// close the stream
eventStream.Close()
// stop the actor system
Expand Down

0 comments on commit 33d0f1b

Please sign in to comment.