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: module context should be immutable #1400

Merged
merged 1 commit into from
May 3, 2024

Conversation

matt2e
Copy link
Collaborator

@matt2e matt2e commented May 3, 2024

fixes: #1398
Now a ModuleContext is built using the following functions:

  • New(moduleName)
  • func (m ModuleContext) Update(configs map[string][]byte, secrets map[string][]byte, databases map[string]Database) ModuleContext
  • func (m ModuleContext) UpdateForTesting(mockVerbs map[schema.RefKey]MockVerb, allowDirectVerbBehavior bool) ModuleContext
  • func (m ModuleContext) UpdateFromEnvironment(ctx context.Context) (ModuleContext, error)
    • (this one will still be split up and changed in an upcoming PR)

ftltest now uses ftltest.Options as an opaque way of building up state to then create a ModuleContext with the above functions. Before we were passing around context.Context and mutating the ModuleContext directly each anything was changed.

And now everything uses the ModuleContext struct directly, rather than with a pointer.

This change won't have any effect on how users write their module unit tests.

@matt2e matt2e requested a review from a team as a code owner May 3, 2024 05:28
@matt2e matt2e requested review from worstell and removed request for a team May 3, 2024 05:28
@alecthomas alecthomas mentioned this pull request May 3, 2024
@matt2e matt2e force-pushed the matt2e/immutable-module-context branch from cdbecf8 to d1811db Compare May 3, 2024 05:33
@matt2e matt2e merged commit e986c3e into main May 3, 2024
10 checks passed
@matt2e matt2e deleted the matt2e/immutable-module-context branch May 3, 2024 06:01
@@ -9,42 +9,35 @@ import (
cf "github.com/TBD54566975/ftl/common/configuration"
)

// FromEnvironment creates a ModuleContext from the local environment.
// UpdateFromEnvironment copies a ModuleContext and gathers configs, secrets and databases from the local environment.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I might be missing something but I don't see where the copy is occurring?

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.

ModuleContext should be immutable to avoid threading issues
2 participants