Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix / Guest list example #297

Merged
merged 1 commit into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions examples/guestlist/memory/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"log"
"sort"
"sync"
"time"

"github.com/google/uuid"
Expand Down Expand Up @@ -57,6 +58,17 @@ func Example() {
eh.NewContextWithNamespace(context.Background(), "simple"),
)

// Setup a test utility waiter that waits for all 11 events to occur before
// evaluating results.
var wg sync.WaitGroup
wg.Add(11)
eventBus.AddHandler(ctx, eh.MatchAll{}, eh.EventHandlerFunc(
func(ctx context.Context, e eh.Event) error {
wg.Done()
return nil
},
))

// Setup the guestlist.
eventID := uuid.New()
guestlist.Setup(
Expand Down Expand Up @@ -89,7 +101,6 @@ func Example() {
if err := commandBus.HandleCommand(ctx, &guestlist.CreateInvite{ID: poseidonID, Name: "Poseidon"}); err != nil {
log.Println("error:", err)
}
time.Sleep(100 * time.Millisecond)

// The invited guests accept and decline the event.
// Note that Athena tries to decline the event after first accepting, but
Expand All @@ -110,14 +121,13 @@ func Example() {
}

// Poseidon is a bit late to the party...
// TODO: Remove sleeps.
time.Sleep(10 * time.Millisecond)
if err := commandBus.HandleCommand(ctx, &guestlist.AcceptInvite{ID: poseidonID}); err != nil {
log.Println("error:", err)
}

// Wait for simulated eventual consistency before reading.
time.Sleep(10 * time.Millisecond)
wg.Wait()
time.Sleep(100 * time.Millisecond)

// Read all invites.
invitationStrs := []string{}
Expand Down
20 changes: 15 additions & 5 deletions examples/guestlist/mongodb/mongodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"log"
"os"
"sort"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -81,6 +82,17 @@ func ExampleIntegration() {
eh.NewContextWithNamespace(context.Background(), "mongodb"),
)

// Setup a test utility waiter that waits for all 11 events to occur before
// evaluating results.
var wg sync.WaitGroup
wg.Add(11)
eventBus.AddHandler(ctx, eh.MatchAll{}, eh.EventHandlerFunc(
func(ctx context.Context, e eh.Event) error {
wg.Done()
return nil
},
))

// Setup the guestlist.
eventID := uuid.New()
guestlist.Setup(
Expand Down Expand Up @@ -118,7 +130,6 @@ func ExampleIntegration() {
if err := commandBus.HandleCommand(ctx, &guestlist.CreateInvite{ID: poseidonID, Name: "Poseidon"}); err != nil {
log.Println("error:", err)
}
time.Sleep(100 * time.Millisecond)

// The invited guests accept and decline the event.
// Note that Athena tries to decline the event after first accepting, but
Expand All @@ -138,15 +149,14 @@ func ExampleIntegration() {
log.Println("error:", err)
}

// Poseidon is a bit late to the party...
// TODO: Remove sleeps.
time.Sleep(100 * time.Millisecond)
// Poseidon is a bit late to the party, will not be accepted...
if err := commandBus.HandleCommand(ctx, &guestlist.AcceptInvite{ID: poseidonID}); err != nil {
log.Println("error:", err)
}

// Wait for simulated eventual consistency before reading.
time.Sleep(100 * time.Millisecond)
wg.Wait()
time.Sleep(1000 * time.Millisecond)

// Read all invites.
invitationStrs := []string{}
Expand Down