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

testing a function that publishes to a topic causes a panic #2184

Closed
mistermoe opened this issue Jul 26, 2024 · 4 comments · Fixed by #2186
Closed

testing a function that publishes to a topic causes a panic #2184

mistermoe opened this issue Jul 26, 2024 · 4 comments · Fixed by #2186
Assignees

Comments

@mistermoe
Copy link
Collaborator

apologies, i don't have time to create an isolated reproducible issue. it would require spending a significant amount of time in order to provide the necessary context.

goroutine 9 [running]:
github.com/TBD54566975/ftl/go-runtime/internal.FromContext(...)
        /REDACTED/PATH/TO/pkg/mod/github.com/!t!b!d54566975/[email protected]/go-runtime/internal/api.go:48
github.com/TBD54566975/ftl/go-runtime/ftl.TopicHandle[...].Publish(0x100edac70?, {0x100ee1c48, 0x140002b6e70}, {{0x1400011aaa0, 0x1e}, {0x1400011aac0, 0x1e}, {0x14000010fd0, 0xf}, 0x1})
        /REDACTED/PATH/TO/pkg/mod/github.com/!t!b!d54566975/[email protected]/go-runtime/ftl/pubsub.go:27 +0xe4
ftl/payments/psm.(*PSM).publishEvent(0x140004add00, {0x100ee1c48, 0x140002b6e70}, {{{{0x0, 0x0}, {0x1400011a964, 0x1a}}}, {{{0x0, 0x0}, {0x1400011a984, ...}}}, ...})
        /REDACTED/PATH/TO/MODULE/payments/psm/psm.go:123 +0x128
ftl/payments/psm.(*PSM).Handle(0x140004add00, {0x100ee1c48, 0x140002b6e70}, {{{{0x0, 0x0}, {0x1400011a964, 0x1a}}}, {{{0x0, 0x0}, {0x1400011a984, ...}}}, ...})
        /REDACTED/PATH/TO/MODULE/payments/psm/psm.go:84 +0xadc
ftl/payments/psm_test.TestHandleWithRetry.func3({0x100ee1c48, 0x140002b6e70}, {{0x1400011a920, 0x1e}, {0x1400011a940, 0x1e}, {0x14000010f40, 0xf}, 0x0})
        /REDACTED/PATH/TO/MODULE/payments/psm/psm_test.go:68 +0x14c
github.com/TBD54566975/ftl/go-runtime/ftl/ftltest.addSubscriber[...].func1({0x100e83400?, 0x140002bf6c0?})
        /REDACTED/PATH/TO/pkg/mod/github.com/!t!b!d54566975/[email protected]/go-runtime/ftl/ftltest/pubsub.go:63 +0xc4
github.com/TBD54566975/ftl/go-runtime/ftl/ftltest.(*fakePubSub).handlePubSubEvent.func1({0x100cc8a75, 0x14}, 0x0?, {0x100e83400?, 0x140002bf6c0?})
        /REDACTED/PATH/TO/pkg/mod/github.com/!t!b!d54566975/[email protected]/go-runtime/ftl/ftltest/pubsub.go:200 +0x54
created by github.com/TBD54566975/ftl/go-runtime/ftl/ftltest.(*fakePubSub).handlePubSubEvent in goroutine 7
        /REDACTED/PATH/TO/pkg/mod/github.com/!t!b!d54566975/[email protected]/go-runtime/ftl/ftltest/pubsub.go:199 +0x9c8
FAIL    ftl/payments/psm        0.309s
@github-actions github-actions bot added the triage Issue needs triaging label Jul 26, 2024
@ftl-robot ftl-robot mentioned this issue Jul 26, 2024
@deniseli
Copy link
Contributor

Looks like this is the panic we're hitting:

// FromContext returns the FTL instance from the context.                                                                                            
func FromContext(ctx context.Context) FTL {
        ftl, ok := ctx.Value(ftlContextKey{}).(FTL)
        if !ok {
                panic("FTL not found in context") <--- right here
        }
        return ftl
}

@mistermoe
Copy link
Collaborator Author

i imagine the issue's originating from somewhere in here

might have something to do with the fact the topic being published to is passed into a function and being called from within that function

@matt2e
Copy link
Collaborator

matt2e commented Jul 26, 2024

FromContext(ctx context.Context)

Sounds like the context was not creating via ftltest.Context(...)
@mistermoe can you confirm that:

  • for the module code: the context you're using to publish to the topic is the same one that was a parameter to the verb
  • for the test code: you made a test context and passed that into the verb you wanted to test

@mistermoe
Copy link
Collaborator Author

confirmed point 1. For point 2, I'm not testing a verb but the same context is being passed through

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 a pull request may close this issue.

3 participants