Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

clock_test.go 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package doppel
  2. import (
  3. "context"
  4. "sync"
  5. "testing"
  6. "time"
  7. "github.com/stretchr/testify/suite"
  8. )
  9. type ClockTestSuite struct {
  10. suite.Suite
  11. clock Clock
  12. wg sync.WaitGroup
  13. ctx context.Context
  14. ctxCancel context.CancelFunc
  15. }
  16. func (suite *ClockTestSuite) SetupTest() {
  17. ctx, cancel := context.WithCancel(context.Background())
  18. suite.ctx = ctx
  19. suite.ctxCancel = cancel
  20. suite.clock = Clock{
  21. stats: &Stats{
  22. k: StatsDefaultK,
  23. lambda: StatsDefaultLambda,
  24. },
  25. tick: make(chan struct{}),
  26. }
  27. suite.wg.Go(func() {
  28. suite.clock.Start(suite.ctx)
  29. })
  30. }
  31. func (suite *ClockTestSuite) TearDownTest() {
  32. suite.ctxCancel()
  33. suite.wg.Wait()
  34. }
  35. func (suite *ClockTestSuite) TestTicks() {
  36. received := 0
  37. for range 3 {
  38. select {
  39. case <-suite.clock.tick:
  40. received++
  41. case <-time.After(2 * time.Second):
  42. suite.Fail("timed out waiting for tick")
  43. }
  44. }
  45. suite.Equal(3, received)
  46. }
  47. func (suite *ClockTestSuite) TestStopsOnCancel() {
  48. select {
  49. case <-suite.clock.tick:
  50. case <-time.After(2 * time.Second):
  51. suite.Fail("timed out waiting for first tick")
  52. }
  53. suite.ctxCancel()
  54. time.Sleep(50 * time.Millisecond)
  55. select {
  56. case <-suite.clock.tick:
  57. suite.Fail("received tick after cancel")
  58. default:
  59. }
  60. }
  61. func TestClock(t *testing.T) {
  62. t.Parallel()
  63. suite.Run(t, &ClockTestSuite{})
  64. }