-
Notifications
You must be signed in to change notification settings - Fork 890
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
Generic hooks for testing #6938
Merged
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
28626dc
initial
dnr 45d620d
use in matching
dnr 18a174d
simplify noop
dnr c4efeac
mock
dnr 1a9615a
fix matching test
dnr 525924c
use test tags for lint
dnr ffeb3e5
rename to testhooks
dnr 64e85cb
copyright
dnr 2a5d4c5
change flag, comments
dnr c2be9e0
Add UpdateWithStart test using hook
stephanos a933ed6
rename
dnr 6194d2c
simplify common case
dnr 6025df7
use int keys
dnr 91193a2
Merge branch 'main' of github.com:temporalio/temporal into david/ei
dnr 2cf3b42
update comments to warn against using it
dnr 0d149a3
fix
dnr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package errorinjector | ||
|
||
const ( | ||
MatchingDisableSyncMatch = "matching.disableSyncMatch" | ||
MatchingLBForceReadPartition = "matching.lbForceReadPartition" | ||
MatchingLBForceWritePartition = "matching.lbForceWritePartition" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//go:build !errorinjector | ||
|
||
package errorinjector | ||
|
||
import "go.uber.org/fx" | ||
|
||
var Module = fx.Options( | ||
fx.Provide(func() (ei ErrorInjector) { return }), | ||
) | ||
|
||
type ( | ||
ErrorInjector struct{} | ||
) | ||
|
||
func Get[T any](ei ErrorInjector, key string) (T, bool) { | ||
var zero T | ||
return zero, false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//go:build errorinjector | ||
|
||
package errorinjector | ||
|
||
import ( | ||
"sync" | ||
|
||
"go.uber.org/fx" | ||
) | ||
|
||
var Module = fx.Options( | ||
fx.Provide(NewTestErrorInjector), | ||
) | ||
|
||
type ( | ||
ErrorInjector interface { | ||
// private accessors; access must go through package-level Get/Set | ||
get(string) (any, bool) | ||
set(string, any) | ||
del(string) | ||
} | ||
|
||
errorInjectorImpl struct { | ||
m sync.Map | ||
} | ||
) | ||
|
||
func Get[T any](ei ErrorInjector, key string) (T, bool) { | ||
if val, ok := ei.get(key); ok { | ||
// this is only used in test so we want to panic on type mismatch: | ||
return val.(T), ok | ||
} | ||
var zero T | ||
return zero, false | ||
} | ||
|
||
func Set[T any](ei ErrorInjector, key string, val T) func() { | ||
ei.set(key, val) | ||
return func() { ei.del(key) } | ||
} | ||
|
||
func NewTestErrorInjector() ErrorInjector { | ||
return &errorInjectorImpl{} | ||
} | ||
|
||
func (ei *errorInjectorImpl) get(key string) (any, bool) { | ||
val, ok := ei.m.Load(key) | ||
return val, ok | ||
} | ||
|
||
func (ei *errorInjectorImpl) set(key string, val any) { | ||
ei.m.Store(key, val) | ||
} | ||
|
||
func (ei *errorInjectorImpl) del(key string) { | ||
ei.m.Delete(key) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to consider flipping this, actually (ie the default being the real impl).
A while ago I experimented with build tags and assertions; and I feel confident that we can add a step for the actual binary build that verifies there's no trace of
ErrorInjector
to be found, as it was optimized away. That way we don't need to tell every single developer to run their tests with this flag (in their IDE etc.).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that, but I'm still a little concerned since we have so many different binary builds (docker images, goreleaser, internal ones), and then users that build their own binaries...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, docker-builds seems to already invoke the server Makefile.