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
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

relay_test.go 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package relay_test
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "github.com/9seconds/mtg/v2/mtglib/internal/relay"
  7. "github.com/stretchr/testify/suite"
  8. )
  9. type RelayTestSuite struct {
  10. suite.Suite
  11. ctx context.Context
  12. ctxCancel context.CancelFunc
  13. r *relay.Relay
  14. }
  15. func (suite *RelayTestSuite) SetupTest() {
  16. suite.ctx, suite.ctxCancel = context.WithCancel(context.Background())
  17. suite.r = relay.AcquireRelay(suite.ctx, loggerMock{}, 4096, time.Second)
  18. }
  19. func (suite *RelayTestSuite) TearDownTest() {
  20. suite.ctxCancel()
  21. relay.ReleaseRelay(suite.r)
  22. suite.r = nil
  23. }
  24. func (suite *RelayTestSuite) TestCancelled() {
  25. suite.ctxCancel()
  26. eastConn := &rwcMock{}
  27. eastConn.Write([]byte{1, 2, 3, 4, 5}) // nolint: errcheck
  28. westConn := &rwcMock{}
  29. westConn.Write([]byte{100, 101, 102}) // nolint: errcheck
  30. suite.Nil(suite.r.Process(eastConn, westConn))
  31. }
  32. func (suite *RelayTestSuite) TestCopyFine() {
  33. eastConn := &rwcMock{}
  34. eastConn.Write([]byte{1, 2, 3, 4, 5}) // nolint: errcheck
  35. westConn := &rwcMock{}
  36. westConn.Write([]byte{100, 101, 102}) // nolint: errcheck
  37. // yes, this test is not good enough. but apparently, if it hangs,
  38. // we can debug most of possible issues.
  39. _ = suite.r.Process(eastConn, westConn)
  40. }
  41. func TestRelay(t *testing.T) {
  42. t.Parallel()
  43. suite.Run(t, &RelayTestSuite{})
  44. }