Skip to content

Flaky test incorrectly determined #8

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

Closed
ag321123 opened this issue Jan 23, 2020 · 5 comments
Closed

Flaky test incorrectly determined #8

ag321123 opened this issue Jan 23, 2020 · 5 comments
Labels
bug Something isn't working invalid This doesn't seem right

Comments

@ag321123
Copy link

ag321123 commented Jan 23, 2020

I am not sure how a flaky test is determined. It seems like a failed test is run again, and the stack tracebacks are compared. I have a very simple example without any non-determinism which is marked flaky, and the tracebacks look the same.

// property based testing used rapid
func TestAbs6(t *testing.T) {
	rapid.Check(t, func(t *rapid.T) {
    value := rapid.Int().Draw(t, "value").(int)
    result := Abs(value)
    if (value * value) != (result * result) {
      t.Errorf("square of result not equal to square of input: %d, result %d\n", value, result)
    }
	})
}

// function to be tested
func Abs(x int) int {
  if x < 0 {
	    return -x
  }
  if x > 15 {
    return x - 1
  }
  return x - 1
}
abs_test.go:89: [rapid] flaky test, can not reproduce a failure
        To try to reproduce, specify -run="TestAbs6" -rapid.seed=1579796179831259001
        Traceback (square of result not equal to square of input: 25541, result 25540
        ):
            /Users/allangold/go/src/github.com/flyingmutant/rapid/engine.go:188 in github.com/flyingmutant/rapid.checkOnce
            /Users/allangold/go/src/github.com/flyingmutant/rapid/engine.go:142 in github.com/flyingmutant/rapid.doCheck
            /Users/allangold/go/src/github.com/flyingmutant/rapid/engine.go:100 in github.com/flyingmutant/rapid.checkTB
            /Users/allangold/go/src/github.com/flyingmutant/rapid/engine.go:71 in github.com/flyingmutant/rapid.Check
            /Users/allangold/go/src/pbt1/abs_test.go:89 in pbt1.TestAbs6
            /usr/local/go/src/testing/testing.go:827 in testing.tRunner
            /usr/local/go/src/runtime/asm_amd64.s:1333 in runtime.goexit
        Original traceback (square of result not equal to square of input: 25541, result 25540
        ):
            /Users/allangold/go/src/github.com/flyingmutant/rapid/engine.go:188 in github.com/flyingmutant/rapid.checkOnce
            /Users/allangold/go/src/github.com/flyingmutant/rapid/engine.go:163 in github.com/flyingmutant/rapid.findBug
            /Users/allangold/go/src/github.com/flyingmutant/rapid/engine.go:134 in github.com/flyingmutant/rapid.doCheck
            /Users/allangold/go/src/github.com/flyingmutant/rapid/engine.go:100 in github.com/flyingmutant/rapid.checkTB
            /Users/allangold/go/src/github.com/flyingmutant/rapid/engine.go:71 in github.com/flyingmutant/rapid.Check
            /Users/allangold/go/src/pbt1/abs_test.go:89 in pbt1.TestAbs6
            /usr/local/go/src/testing/testing.go:827 in testing.tRunner
            /usr/local/go/src/runtime/asm_amd64.s:1333 in runtime.goexit
        Failed test output:
    abs_test.go:90: [rapid] draw value: 25541
    abs_test.go:93: square of result not equal to square of input: 25541, result 25540
@flyingmutant
Copy link
Owner

Can you please try the latest master (import path is now pgregory.net/rapid)? . This is what I get (on both Windows and Linux, can't test on OS X right now):

λ go test -run=Abs6
--- FAIL: TestAbs6 (0.00s)
    failure_external_test.go:133: [rapid] failed after 1 tests: square of result not equal to square of input: 0, result -1

        To reproduce, specify -run="TestAbs6" -rapid.seed=1579804795669640702
        Failed test output:
    failure_external_test.go:134: [rapid] draw value: 0
    failure_external_test.go:137: square of result not equal to square of input: 0, result -1
FAIL
exit status 1
FAIL    pgregory.net/rapid      0.547s

@ag321123
Copy link
Author

ag321123 commented Jan 23, 2020 via email

@flyingmutant
Copy link
Owner

Great!

I've found go module system to be a little flaky when it comes to changes of import path. E.g. for me, https://play.golang.org/p/ZdNjIGzT_EX says

go: finding pgregory.net/rapid v0.2.2
go: downloading pgregory.net/rapid v0.2.2
go: extracting pgregory.net/rapid v0.2.2
go: pgregory.net/rapid: pgregory.net/[email protected]: parsing go.mod:
	module declares its path as: github.com/flyingmutant/rapid
	        but was required as: pgregory.net/rapid

which is bogus, because the only published version of pgregory.net/rapid is v0.3.0. This may be related to the issue you've reported: change of import path affects tracebacks, which are used to check for flakiness.

@flyingmutant flyingmutant added bug Something isn't working invalid This doesn't seem right labels Jan 23, 2020
@pgaskin
Copy link

pgaskin commented Jan 24, 2020

The playground import should work properly now. The issue is that the playground uses modules from proxy.golang.org, which only gets updated when someone tries to get a version from it. In addition, the playground caches results, including errors.

To fix this kind of thing in the future, just run go get pgregory.net/[email protected] from within a Go module to force the release to be cached. To force a Go playground run to bypass the cache, just add whitespace or some other trivial change.

https://play.golang.org/p/IZ4XfquYYFG

https://pkg.go.dev/pgregory.net/[email protected]?tab=versions

@flyingmutant
Copy link
Owner

Thanks for the information; it is unfortunate to have to work around the playground cache.

I did try the v0.3.0 in a local Go module immediately after pushing the tag to ensure that everything is working.

The weird thing is, sometimes playground did work, so playground cache is not always used; also, the cache is not shared between different playground URLs, which is unexpected.

flyingmutant added a commit that referenced this issue Jan 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants