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

Watch events during linearizability test and compare history #15044

Merged
merged 2 commits into from
Jan 10, 2023

Conversation

serathius
Copy link
Member

@codecov-commenter
Copy link

codecov-commenter commented Dec 24, 2022

Codecov Report

Merging #15044 (221d2bb) into main (108cd9a) will decrease coverage by 0.34%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main   #15044      +/-   ##
==========================================
- Coverage   74.95%   74.60%   -0.35%     
==========================================
  Files         415      415              
  Lines       34288    34288              
==========================================
- Hits        25700    25580     -120     
- Misses       6970     7069      +99     
- Partials     1618     1639      +21     
Flag Coverage Δ
all 74.60% <ø> (-0.35%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
server/proxy/grpcproxy/register.go 50.00% <0.00%> (-25.00%) ⬇️
server/etcdserver/api/rafthttp/peer_status.go 87.87% <0.00%> (-12.13%) ⬇️
server/etcdserver/api/v3rpc/util.go 70.96% <0.00%> (-9.68%) ⬇️
server/etcdserver/api/rafthttp/peer.go 87.01% <0.00%> (-8.45%) ⬇️
client/pkg/v3/tlsutil/tlsutil.go 83.33% <0.00%> (-8.34%) ⬇️
client/v3/leasing/util.go 91.66% <0.00%> (-6.67%) ⬇️
client/pkg/v3/testutil/leak.go 62.83% <0.00%> (-4.43%) ⬇️
server/storage/mvcc/watchable_store.go 89.85% <0.00%> (-3.63%) ⬇️
server/etcdserver/api/rafthttp/msgappv2_codec.go 71.30% <0.00%> (-3.48%) ⬇️
server/etcdserver/api/v3rpc/watch.go 85.39% <0.00%> (-2.86%) ⬇️
... and 20 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@serathius serathius changed the title [tests] Watch events during linearizability test and compare history Watch events during linearizability test and compare history Dec 24, 2022
@serathius
Copy link
Member Author

PTAL @ahrtr

Comment on lines 100 to 123
trafficCtx, trafficCancel := context.WithCancel(ctx)
go func() {
defer cancel()
err := triggerFailpoints(ctx, t, clus, failpoint)
if err != nil {
t.Error(err)
}
defer trafficCancel()
triggerFailpoints(ctx, t, clus, failpoint)
// Wait second to collect traffic after triggering last failpoint.
time.Sleep(time.Second)
}()
operations := simulateTraffic(ctx, t, clus, traffic)
watchCtx, watchCancel := context.WithCancel(ctx)
var operations []porcupine.Operation
go func() {
defer watchCancel()
operations = simulateTraffic(trafficCtx, t, clus, traffic)
// Wait second to collect watch events after all traffic was sent.
time.Sleep(time.Second)
}()
events := watchClusterChanges(watchCtx, t, clus)
Copy link
Member

Choose a reason for hiding this comment

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

You'd better add comment to explain the relationship between three kinds of goroutines and how they are related by the cancel functions,

  • The triggering failpoint goroutine
  • The simulating traffic goroutine
  • The watching event goroutines.

Copy link
Member Author

Choose a reason for hiding this comment

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

Comments should explain "why?" and not "what?". Isn't it clear in:

go func() {
		defer trafficCancel()
		triggerFailpoints(ctx, t, clus, failpoint)
		// Wait second to collect traffic after triggering last failpoint.
		time.Sleep(time.Second)
	}()

The failpoints gorouting cancels traffic?

Copy link
Member

Choose a reason for hiding this comment

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

Isn't it clear

It's clear to you because you are the author. It doesn't mean it's clear to other contributors. If I understood it correctly, the The triggering failpoint goroutine stops the simulating traffic goroutine by executing defer trafficCancel(), and the simulating traffic goroutine stops the watching event goroutines by defer watchCancel().

Note that it isn't Intuitive at first look. I was even thinking it might be a copy-paste typo, because I was confused why you use ctx, but defer cancel the trafficCancel.

It isn't the first time I raise similar comment. Please always keep in mind to add as much self-contained comment as possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's clear to you because you are the author. It doesn't mean it's clear to other contributors.

This is a very vague generic statement. Code is clean or it's not. If concept of using context to propagate stop signal is not familiar or standard then let's rewrite it. It's not about throwing as many comments as possible as it doesn't solve the problem with code.

Moved the code to separate function added comment explaining idea to use context to propagate cancellation.

tests/linearizability/linearizability_test.go Outdated Show resolved Hide resolved
@serathius serathius force-pushed the linearizability-watch branch from eedbb50 to c4ea991 Compare January 1, 2023 18:07
@serathius serathius force-pushed the linearizability-watch branch 2 times, most recently from 7640095 to 221d2bb Compare January 9, 2023 13:56
@serathius
Copy link
Member Author

PTAL @ahrtr @ptabor

tests/linearizability/watch.go Outdated Show resolved Hide resolved
tests/linearizability/watch.go Show resolved Hide resolved
@@ -196,6 +204,18 @@ type trafficConfig struct {
traffic Traffic
}

func validateEventsMatch(t *testing.T, ops [][]watchEvent) {
for i := 1; i < len(ops); i++ {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment describing when we expect different lengths... (one node off/partitioned during the test).

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

tests/linearizability/linearizability_test.go Outdated Show resolved Hide resolved
tests/linearizability/linearizability_test.go Outdated Show resolved Hide resolved
@serathius serathius force-pushed the linearizability-watch branch from 221d2bb to 57dfc87 Compare January 10, 2023 13:49
@serathius serathius force-pushed the linearizability-watch branch from 57dfc87 to 8a9f848 Compare January 10, 2023 14:13

func collectClusterWatchEvents(ctx context.Context, t *testing.T, clus *e2e.EtcdProcessCluster) [][]watchEvent {
mux := sync.Mutex{}
var wg sync.WaitGroup
Copy link
Contributor

Choose a reason for hiding this comment

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

consider errgroup as well

Copy link
Member Author

Choose a reason for hiding this comment

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

Will follow this up

@serathius serathius merged commit ff89864 into etcd-io:main Jan 10, 2023
@serathius serathius deleted the linearizability-watch branch June 15, 2023 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants