streamproxy_test.go 993 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package streamproxy_test
  2. import (
  3. "testing"
  4. "time"
  5. "imuslab.com/zoraxy/mod/streamproxy"
  6. )
  7. func TestPort2Port(t *testing.T) {
  8. // Create a stopChan to control the loop
  9. stopChan := make(chan bool)
  10. // Create a ProxyRelayConfig with dummy values
  11. config := &streamproxy.ProxyRelayConfig{
  12. Timeout: 1,
  13. }
  14. // Run port2port in a separate goroutine
  15. t.Log("Starting go routine for proxy service")
  16. go func() {
  17. err := config.Port2host("8080", "124.244.86.40:8080", stopChan)
  18. if err != nil {
  19. t.Errorf("port2port returned an error: %v", err)
  20. }
  21. }()
  22. // Let the goroutine run for a while
  23. time.Sleep(20 * time.Second)
  24. // Send a stop signal to stopChan
  25. t.Log("Sending over stop signal")
  26. stopChan <- true
  27. // Allow some time for the goroutine to exit
  28. time.Sleep(1 * time.Second)
  29. // If the goroutine is still running, it means it did not stop as expected
  30. if config.IsRunning() {
  31. t.Errorf("port2port did not stop as expected")
  32. }
  33. }