Browse Source

Fix quic test

- Cannot rely on receiving client connection
  termination message, so set a short server
  idle timeout to ensure the test completes
  on time.
Rod Hynes 7 years ago
parent
commit
058d03822c
2 changed files with 14 additions and 1 deletions
  1. 4 1
      psiphon/common/quic/quic.go
  2. 10 0
      psiphon/common/quic/quic_test.go

+ 4 - 1
psiphon/common/quic/quic.go

@@ -62,6 +62,9 @@ const (
 	CLIENT_IDLE_TIMEOUT      = 30 * time.Second
 )
 
+// quic_test overrides the server idle timeout.
+var serverIdleTimeout = SERVER_IDLE_TIMEOUT
+
 // Listener is a net.Listener.
 type Listener struct {
 	quic_go.Listener
@@ -88,7 +91,7 @@ func Listen(addr string) (*Listener, error) {
 
 	quicConfig := &quic_go.Config{
 		HandshakeTimeout:      SERVER_HANDSHAKE_TIMEOUT,
-		IdleTimeout:           SERVER_IDLE_TIMEOUT,
+		IdleTimeout:           serverIdleTimeout,
 		MaxIncomingStreams:    1,
 		MaxIncomingUniStreams: -1,
 		KeepAlive:             true,

+ 10 - 0
psiphon/common/quic/quic_test.go

@@ -47,6 +47,16 @@ func runQUIC(t *testing.T, negotiateQUICVersion string) {
 	serverReceivedBytes := int64(0)
 	clientReceivedBytes := int64(0)
 
+	// Intermittently, on some platforms, the client connection termination
+	// packet is not received even when sent/received locally; set a brief
+	// idle timeout to ensure the server-side client handler doesn't block too
+	// long on Read, causing the test to fail.
+	//
+	// In realistic network conditions, and especially under adversarial
+	// network conditions, we should not expect to regularly receive client
+	// connection termination packets.
+	serverIdleTimeout = 1 * time.Second
+
 	listener, err := Listen("127.0.0.1:0")
 	if err != nil {
 		t.Fatalf("Listen failed: %s", err)