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

feat: ftltest supports pubsub #1736

Merged
merged 4 commits into from
Jun 12, 2024
Merged

feat: ftltest supports pubsub #1736

merged 4 commits into from
Jun 12, 2024

Conversation

matt2e
Copy link
Collaborator

@matt2e matt2e commented Jun 11, 2024

closes #1598

Adds:

  • By default, disables all subscribers during unit tests
  • Subscribers can be manually added per unit test
    • Subscribers can be actual sinks, or ad-hoc ones defined in the test (just define a func in the argument)
  • Check what events were published to a topic
  • Check what events were consumed by a subscription, and whether an error occured
  • Allow the unit test to wait for all events to be consumed
  • Unit tests can publish to external module's topics

@matt2e matt2e requested a review from alecthomas as a code owner June 11, 2024 07:26
@matt2e matt2e requested review from a team and worstell and removed request for a team June 11, 2024 07:26
@ftl-robot ftl-robot mentioned this pull request Jun 11, 2024
}

type SubscriptionHandle[E any] struct {
Topic *schema.Ref
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TopicHandle and SubscriptionHandle's fields are accessed by ftltest, so have been made public

fsm: newFakeFSMManager(),
mockMaps: map[uintptr]mapImpl{},
allowMapCalls: false,
configValues: map[string][]byte{},
secretValues: map[string][]byte{},
globalTopic: pubsub.New[pubSubEvent](),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's pull all the pubsub code out into a separate struct and file, and forward to it from fakeFTL.

go-runtime/ftl/ftltest/fake.go Outdated Show resolved Hide resolved
go-runtime/ftl/ftltest/fake.go Outdated Show resolved Hide resolved
go-runtime/ftl/ftltest/fake.go Outdated Show resolved Hide resolved
go-runtime/ftl/ftltest/fake.go Outdated Show resolved Hide resolved
go-runtime/ftl/ftltest/fake.go Outdated Show resolved Hide resolved
defer f.pubSubLock.Unlock()

logger := log.FromContext(ctx).Scope("pubsub")
results := []SubscriptionResult[E]{}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
results := []SubscriptionResult[E]{}
var results []SubscriptionResult[E]

tip: avoids an allocation

go-runtime/ftl/ftltest/fake.go Outdated Show resolved Hide resolved
go-runtime/ftl/ftltest/ftltest.go Outdated Show resolved Hide resolved
google.golang.org/protobuf v1.34.1 // indirect
)

replace github.com/TBD54566975/ftl => ./../../../../../..
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a lotta dots

@matt2e matt2e force-pushed the matt2e/ftltest-pubsub branch from 8fb5b5f to 8bdce7b Compare June 12, 2024 03:40
@matt2e matt2e merged commit ff66550 into main Jun 12, 2024
40 checks passed
@matt2e matt2e deleted the matt2e/ftltest-pubsub branch June 12, 2024 03:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add runtime safety checks when publishing to external topics ftltest support for PubSub
2 participants