-
Notifications
You must be signed in to change notification settings - Fork 82
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
Cache the replay event in case we get multiple new client connections #189
Merged
eli-darkly
merged 2 commits into
launchdarkly:contrib
from
moshegood:cache.replay.event
Jun 13, 2022
Merged
Changes from all commits
Commits
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
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ package streams | |
|
||
import ( | ||
"errors" | ||
"time" | ||
|
||
"github.com/launchdarkly/ld-relay/v6/config" | ||
"github.com/launchdarkly/ld-relay/v6/internal/core/sharedtest" | ||
|
@@ -49,13 +50,17 @@ type mockStoreQueries struct { | |
fakeSegmentsError error | ||
flags []ldstoretypes.KeyedItemDescriptor | ||
segments []ldstoretypes.KeyedItemDescriptor | ||
latency time.Duration | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this for testing concurrent calls to Replay - to ensure we have both calls use the same flightgroup. |
||
} | ||
|
||
func (q mockStoreQueries) IsInitialized() bool { | ||
return q.initialized | ||
} | ||
|
||
func (q mockStoreQueries) GetAll(kind ldstoretypes.DataKind) ([]ldstoretypes.KeyedItemDescriptor, error) { | ||
if q.latency > 0 { | ||
time.Sleep(q.latency) | ||
} | ||
switch kind { | ||
case ldstoreimpl.Features(): | ||
return q.flags, q.fakeFlagsError | ||
|
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.
As part of the unit test polishing work I'm doing, I'm changing how this one works because I think there's a logic error in it.
The test on line 282 does not, I think, actually verify that the computation was not done twice:
event1 != event2
is comparing two interface values, and in Go that is not a reference equality test (as in, "are they literally the same instance of the type"), it is a test of whether they have the same concrete types and whether their values as those concrete types are equal. In other words, ifa
andb
are separately created instances of some struct type and their fields have the same values, and you cast them both to some interface type, the resulting interface values are equal. And since the data store in this case returns the same flag/segment data every time it is queried (the same empty data, since it was created with flags and segments ofnil
), this test can't possibly fail. So I'm implementing this differently, using a store that is instrumented to return different data for each query.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.
Sorry, my previous comment was not quite right. The test as written does work, in that if I remove the actual fix and run the new test, the test does fail— it detects inequality of the events on line 282. However, that is because of an implementation detail that I'd rather not rely on: the use of the
streams.deferredEvent
type, which memoizes the value of the event. That forces Go to treat the equality test as reference equality because the type contains things that can't be compared by value. But if the concrete types ofevent1
andevent2
were a simpler struct type that just had fields for the event name and data, then line 282 would not work. I'd rather have this test be independent of such implementation details that aren't directly relevant to the logic we're testing, so I still think it's best to use an instrumented store as I described.