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

Review time.sleep in tests #279

Open
3 of 12 tasks
ayuryshev opened this issue Apr 9, 2019 · 2 comments
Open
3 of 12 tasks

Review time.sleep in tests #279

ayuryshev opened this issue Apr 9, 2019 · 2 comments

Comments

@ayuryshev
Copy link
Collaborator

ayuryshev commented Apr 9, 2019

Task(s)

  1. Examine tests using time.Sleep. Examine stability of test before start of work:
go clean -testcache || go test ./pkg/[package]/...   # repeat 10 or more times

or

go clean -testcache || go test -timeout 1m github.com/skycoin/skywire/pkg/[package] -run [name of test]

note random FAILs if they will occure.

  1. Try to eliminate time.Sleep from tests without changing their behaviour
  2. In case if time.Sleep is justified - write a comment describing "why time.Sleep is justified in this test"
  3. Check stability of test after changes in the same way

Tests with time.Sleep

  • internal/noise/net_test.go:2
  • internal/therealproxy/server_test.go:2
  • internal/therealssh/channel_pty_test.go:4
  • internal/therealssh/channel_test.go:3
  • internal/therealssh/client_test.go:1
  • pkg/app/app_test.go:1
  • pkg/messaging/client_test.go:6
  • pkg/messaging/pool_test.go:2
  • pkg/node/node_test.go:3
  • pkg/node/rpc_test.go:2
  • pkg/router/router_test.go:15
  • pkg/transport/manager_test.go:5
@ayuryshev ayuryshev changed the title Cleanup. Eliminate or justify using of time.Sleep in tests Cleanup. Eliminate or justify time.Sleep in tests Apr 16, 2019
@jdknives jdknives changed the title Cleanup. Eliminate or justify time.Sleep in tests Review time.sleep in tests May 4, 2019
@jdknives
Copy link
Member

@Darkren on Discord:

I didn’t get the intent of this. Based on the issue description I suppose that tests with time.Sleep behave unstable, but I’m not sure about that. I’d say that unstable code will be unstable with or without time.Sleep. The only problem I see with time.Sleep is that a lot of such calls may exceed test timeout, thus leading to failure

@ayuryshev
Copy link
Collaborator Author

ayuryshev commented Jun 27, 2019

Those tests has at least one defect - their duration is always time.Sleep duration + time of test itself.
I propose to cleanup them in a way described in: https://speakerdeck.com/mitchellh/advanced-testing-with-go?slide=62

...
select {
   case <- thingHappened:
   case <- time.After(delay):
     t.Fatal("timeout")
}

I counted 50 cases of using time.Sleep in *test.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants