Skip to content

Commit

Permalink
unit test repro of issue #2266
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanj-square committed Aug 8, 2024
1 parent 1bb1268 commit 17048f4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions go-runtime/ftl/ftltest/testdata/go/pubsub/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (

//ftl:export
var Topic = ftl.Topic[Event]("topic")

//ftl:export
var Topic2 = ftl.Topic[Event]("topic2")

var subscription = ftl.Subscription(Topic, "subscription")

//ftl:data
Expand All @@ -23,6 +27,11 @@ func PublishToTopicOne(ctx context.Context, event Event) error {
return Topic.Publish(ctx, event)
}

//ftl:verb
func PublishToTopicTwo(ctx context.Context, event Event) error {
return Topic2.Publish(ctx, event)
}

//ftl:subscribe subscription
func ErrorsAfterASecond(ctx context.Context, event Event) error {
time.Sleep(1 * time.Second)
Expand Down
11 changes: 11 additions & 0 deletions go-runtime/ftl/ftltest/testdata/go/pubsub/pubsub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ func TestSubscriberReturningErrors(t *testing.T) {
assert.Equal(t, count, len(ftltest.EventsForTopic(ctx, Topic)))
}

func TestPropagateEvents(t *testing.T) {
// Test that we can publish multiple events, which will take time to consume, and that we track each error
ctx := ftltest.Context(
ftltest.WithSubscriber(subscription, PublishToTopicTwo),
)
assert.NoError(t, PublishToTopicOne(ctx, Event{Value: "propagation-test"}))
ftltest.WaitForSubscriptionsToComplete(ctx)
assert.Equal(t, 1, len(ftltest.EventsForTopic(ctx, Topic)))
assert.Equal(t, 1, len(ftltest.EventsForTopic(ctx, Topic2)))
}

func TestMultipleMultipleFakeSubscribers(t *testing.T) {
// Test that multiple adhoc subscribers can be added for a subscription
count := 5
Expand Down

0 comments on commit 17048f4

Please sign in to comment.