-
Notifications
You must be signed in to change notification settings - Fork 35
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
Implement sleep failpoint status/counter for linearizability test cases #37
Conversation
cc @serathius |
runtime/http.go
Outdated
@@ -72,6 +72,13 @@ func (*httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |||
lines[i] = fps[i] + "=" + s | |||
} | |||
w.Write([]byte(strings.Join(lines, "\n") + "\n")) | |||
} else if strings.HasSuffix(key, "/count") { | |||
fp := key[:len(key)-6] |
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.
fp := key[:len(key)-6] | |
fp := key[:len(key)-len("/count")] |
runtime/runtime.go
Outdated
@@ -114,6 +114,25 @@ func Status(failpath string) (string, error) { | |||
return t.desc, nil | |||
} | |||
|
|||
// StatusCount gives the number of sleeps executed on the current terms |
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.
// StatusCount gives the number of sleeps executed on the current terms | |
// StatusCount gives the how many times current term was executed |
runtime/terms.go
Outdated
@@ -41,6 +41,8 @@ type terms struct { | |||
|
|||
// mu protects the state of the terms chain | |||
mu sync.Mutex | |||
// counts amount of sleep executions |
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.
// counts amount of sleep executions | |
// counts amount of executions |
runtime/terms.go
Outdated
@@ -310,6 +312,9 @@ func actSleep(t *term) interface{} { | |||
return nil | |||
} | |||
time.Sleep(dur) | |||
t.parent.mu.Lock() | |||
t.parent.counter++ |
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.
Could we count number of any executions instead of just sleep?
Overall looks good, however let's count any execution instead of only sleep ones. |
d4701a0
to
2ce0575
Compare
@serathius, implemented fixes as per your suggestions. |
@@ -72,6 +72,13 @@ func (*httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |||
lines[i] = fps[i] + "=" + s | |||
} | |||
w.Write([]byte(strings.Join(lines, "\n") + "\n")) | |||
} else if strings.HasSuffix(key, "/count") { |
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.
API could be improved to something more RESTy, but this should work for now.
@@ -114,6 +114,25 @@ func Status(failpath string) (string, error) { | |||
return t.desc, nil | |||
} | |||
|
|||
// StatusCount outputs how many times current term was executed | |||
func StatusCount(failpath string) (string, error) { |
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 would expect that StatusCount
function should return an int
instead of string
. However that can be fixed in future PRs.
runtime/termscounter_test.go
Outdated
name: "runtime_test/ExampleString", | ||
desc: `10*sleep(10)->1*return("abc")`, | ||
run: 12, | ||
want: "11", |
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.
If you run loop 12
times, how the result is 11
?
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.
this happens because we are building terms here by saying:
desc:
10sleep(10)->1return("abc"),
sleep exactly 10 times and then return 1 time.
Even if the function is called more than 11 times, no terms will be executed, because its controlled by internal counter:
func (mc *modCount) allow() bool { if mc.c > 0 { mc.c-- return true } return false }
That way we can check if the fail point is executed exactly 11 times and not the number of function calls.
runtime/termscounter_test.go
Outdated
want string | ||
}{ | ||
{ | ||
name: "runtime_test/ExampleString", |
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.
Could you add more tests scenarios? For example: Before enable, after disable, after changing term 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.
done
}, | ||
} | ||
|
||
for _, tc := range testcases { |
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.
If you want to use table tests, please use subtests.
In this case I think it's ok to disable the lint rule on those lines by adding a comment
|
@@ -41,6 +41,8 @@ type terms struct { | |||
|
|||
// mu protects the state of the terms chain | |||
mu sync.Mutex | |||
// counts executions | |||
counter int |
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.
Why add this field?
Note: when you implement any new feature or do any enhancement, please clarify the requirement first. I do not get the info from the description. Please also make sure you read design.md. Note that the existing design & implementation already supports counter. For example,
|
Requirements were discussed in etcd-io/etcd#14796, unfortunatelly issue was not correctly linked. |
If you really need more visibility of the terms, I would suggest to enhance the existing |
`gofail --version` should exit with 0
Each time terms is executed the counter is incremented. Added counter endpoint that gives number of executions on the current terms: GET pkg/failpoint/count When DELETE /pkg/failpoint is executed, failpoint.terms is nilled, hence counter is reset. Requested in reference to: tests/linearizability: added sleep fail point injection #14796 Signed-off-by: Ramil Mirhasanov <ramil600@yahoo.com> runtime: added test cases for terms counter
8b27907
to
484bc5b
Compare
implemented more testcases, please let me know if you would like me to implement any changes to the http endpoints |
@ramil600 are you still working on this PR? No rush, but please reply, otherwise I'll take over in couple days. |
@lavacat, sorry for late reply, I was working on it, but there was no resolution from maintainers, on whether my PR should be merged. If you can help me, I am willing complete this one, please review my submitted PR. |
@ramil600 I've looked at the PR.
|
Yes, please feel free to follow this direction to work on this task. But please keep it backward compatible, which means it shouldn't break anything on the existing etcd's linearizablity test.
The existing logic on term isn't perfect, but it meets the requirement of the etcd test for now. We can enhance it on demand. I thought about refactoring& enhancing the overall design (e.g. adding |
In order to keep the function signature same @ahrtr, please let me know what do you think about it? Currently I added StatusCount() function in the same PR, that counts executions with help of new terms.counter variable. |
I think it will break logic for checking if failpoint is Available IMO, we should define Status output as json and then refactor etcd fetchFailpoints Since this is blocking sleep failpoints impl I'm ok with merging current @ramil600 please also address points 3 and 4 in #37 (comment) |
@ramil600 are you still working on this? If you won't reply by May 15th, I'll assume you are busy and I'll look for somebody to take over. You'll still be the author of the commit. IMO this is very close to done if we stick with |
I have attempted to update Ramil's code to run successfully in #47. If Ramil wants to take it up he can continue or I can start fixing issues listed in #37 (comment). @ramil600 is still the author of the original commit. |
Closing for #47 |
Each time sleep is executed in actSleep counter is incremented. Added counter endpoint that gives number of sleeps executed on the current terms: GET pkg/failpoint/count When DELETE /pkg/failpoint is executed, failpoint.terms is nilled, hence counter is reset.
Requested in reference to:
tests/linearizability: added sleep fail point injection #14796
Signed-off-by: Ramil Mirhasanov ramil600@yahoo.com