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 kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

updater_test.go 898B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package dc
  2. import (
  3. "sync"
  4. "testing"
  5. "time"
  6. "github.com/stretchr/testify/suite"
  7. )
  8. type UpdaterTestSuite struct {
  9. UpdaterTestSuiteBase
  10. u updater
  11. }
  12. func (s *UpdaterTestSuite) SetupTest() {
  13. s.UpdaterTestSuiteBase.SetupTest()
  14. s.u = updater{
  15. logger: s.loggerMock,
  16. period: 100 * time.Millisecond,
  17. }
  18. }
  19. func (s *UpdaterTestSuite) TestPeriodicUpdates() {
  20. ticker := time.NewTicker(10 * time.Millisecond)
  21. defer ticker.Stop()
  22. lock := &sync.Mutex{}
  23. collected := []time.Time{}
  24. go s.u.run(s.ctx, func() error {
  25. select {
  26. case <-s.ctx.Done():
  27. case value := <-ticker.C:
  28. lock.Lock()
  29. collected = append(collected, value)
  30. lock.Unlock()
  31. }
  32. return nil
  33. })
  34. s.Eventually(func() bool {
  35. lock.Lock()
  36. defer lock.Unlock()
  37. return len(collected) == 3
  38. }, time.Second, 10*time.Millisecond)
  39. }
  40. func TestUpdater(t *testing.T) {
  41. t.Parallel()
  42. suite.Run(t, &UpdaterTestSuite{})
  43. }