Skip to content

Commit

Permalink
update design doc and move tests
Browse files Browse the repository at this point in the history
Signed-off-by: ZhouJianMS <zhoujian@microsoft.com>
  • Loading branch information
ZhouJianMS committed Nov 9, 2023
1 parent 3b612e3 commit dc10eb8
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 161 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ List the failpoints,
$ curl http://127.0.0.1:1234/SomeFuncString=return("hello")
```

Retrieve the execution count of a failpoint,

```sh
$curl http://127.0.0.1:1234/SomeFuncString/execution-count -XGET
```

Deactivate a failpoint,

```sh
Expand Down
10 changes: 10 additions & 0 deletions doc/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ Similarly, you can set multiple failpoints using endpoint `/failpoints`,
curl http://127.0.0.1:22381/failpoints -X PUT -d'failpoint1=return("hello");failpoint2=sleep(10)'
```

You can get the execution count of the failpoint in the dynamic way,
```
$curl http://127.0.0.1:1234/SomeFuncString/execution-count -XGET
```

To deactivate a failpoint,
```
$ curl http://127.0.0.1:1234/SomeFuncString -XDELETE
```

#### 3.2 Unit test
Assuming there is a function with a failpoint something like below,
```
Expand Down
4 changes: 2 additions & 2 deletions runtime/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ 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)-len("/count")]
} else if strings.HasSuffix(key, "/execution-count") {
fp := key[:len(key)-len("/execution-count")]
_, count, err := status(fp)
if err != nil {
if err == ErrNoExist {
Expand Down
2 changes: 1 addition & 1 deletion runtime/terms.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (t *terms) eval() interface{} {
for _, term := range t.chain {
if term.mods.allow() {
t.counter++
return term.do(), nil
return term.do()
}
}
return nil
Expand Down
43 changes: 43 additions & 0 deletions runtime/terms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,46 @@ func TestTermsTypes(t *testing.T) {
}
}
}


Check failure on line 75 in runtime/terms_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed (goimports)
func TestTermsCounter(t *testing.T) {
tests := []struct {
failpointTerm string
runAfterEnabling int
wantCount int
}{
{
failpointTerm: `10*sleep(10)->1*return("abc")`,
runAfterEnabling: 12,
// This example tests mods which allows users to restrict the
// number of failpoint actions as against their callsite executions.
// This is the reason why wantCount < runAfterEnabling
// In a real world example you can hit a code spot a million times but
// using mods restrict the associated fallpoint actions to run twice.
wantCount: 11,
},
{
failpointTerm: `10*sleep(10)->1*return("abc")`,
runAfterEnabling: 3,
wantCount: 3,
},
{
failpointTerm: `10*sleep(10)->1*return("abc")`,
runAfterEnabling: 0,
wantCount: 0,
},
}
for _, tt := range tests {
ter, err := newTerms("test", tt.failpointTerm)
if err != nil {
t.Fatal(err)
}
for i := 0; i < tt.runAfterEnabling; i++ {
_ = ter.eval()
}

if ter.counter != tt.wantCount {
t.Fatalf("counter is not properly incremented")
}
}
}
158 changes: 0 additions & 158 deletions runtime/termscounter_test.go

This file was deleted.

0 comments on commit dc10eb8

Please sign in to comment.