Files
zoraxy/src/mod/streamproxy/streamproxy_test.go
Toby Chui 2d611a559a Optimized structure for stream proxy
- Separated instance and config for stream proxy
2025-07-02 21:03:57 +08:00

44 lines
952 B
Go

package streamproxy_test
import (
"testing"
"time"
"imuslab.com/zoraxy/mod/streamproxy"
)
func TestPort2Port(t *testing.T) {
// Create a stopChan to control the loop
stopChan := make(chan bool)
// Create a ProxyRelayConfig with dummy values
config := &streamproxy.ProxyRelayInstance{
Timeout: 1,
}
// Run port2port in a separate goroutine
t.Log("Starting go routine for proxy service")
go func() {
err := config.Port2host("8080", "124.244.86.40:8080", stopChan)
if err != nil {
t.Errorf("port2port returned an error: %v", err)
}
}()
// Let the goroutine run for a while
time.Sleep(20 * time.Second)
// Send a stop signal to stopChan
t.Log("Sending over stop signal")
stopChan <- true
// Allow some time for the goroutine to exit
time.Sleep(1 * time.Second)
// If the goroutine is still running, it means it did not stop as expected
if config.IsRunning() {
t.Errorf("port2port did not stop as expected")
}
}