Эх сурвалжийг харах

Fix: update memory_test to use context

Rod Hynes 8 жил өмнө
parent
commit
491dc59216

+ 1 - 1
psiphon/controller_test.go

@@ -1041,7 +1041,7 @@ func initDisruptor() {
 			localConn, err := listener.AcceptSocks()
 			if err != nil {
 				if e, ok := err.(net.Error); ok && e.Temporary() {
-					fmt.Printf("disruptor proxy temporary accept error: %s", err)
+					fmt.Printf("disruptor proxy temporary accept error: %s\n", err)
 					continue
 				}
 				fmt.Printf("disruptor proxy accept error: %s\n", err)

+ 8 - 4
psiphon/memory_test/memory_test.go

@@ -20,6 +20,7 @@
 package memory_test
 
 import (
+	"context"
 	"encoding/json"
 	"fmt"
 	"io/ioutil"
@@ -127,7 +128,8 @@ func runMemoryTest(t *testing.T, testMode int) {
 	}
 
 	var controller *psiphon.Controller
-	var controllerShutdown chan struct{}
+	var controllerCtx context.Context
+	var controllerStopRunning context.CancelFunc
 	var controllerWaitGroup *sync.WaitGroup
 	restartController := make(chan bool, 1)
 	reconnectTunnel := make(chan bool, 1)
@@ -179,21 +181,23 @@ func runMemoryTest(t *testing.T, testMode int) {
 			t.Fatalf("error creating controller: %s", err)
 		}
 
-		controllerShutdown = make(chan struct{})
+		controllerCtx, controllerStopRunning = context.WithCancel(context.Background())
 		controllerWaitGroup = new(sync.WaitGroup)
+
 		controllerWaitGroup.Add(1)
 		go func() {
 			defer controllerWaitGroup.Done()
-			controller.Run(controllerShutdown)
+			controller.Run(controllerCtx)
 		}()
 	}
 
 	stopController := func() {
-		close(controllerShutdown)
+		controllerStopRunning()
 		controllerWaitGroup.Wait()
 	}
 
 	testTimer := time.NewTimer(testDuration)
+	defer testTimer.Stop()
 	memInspectionTicker := time.NewTicker(memInspectionFrequency)
 	lastTunnelsEstablished := int32(0)
 

+ 1 - 1
psiphon/remoteServerList_test.go

@@ -322,7 +322,7 @@ func testObfuscatedRemoteServerLists(t *testing.T, omitMD5Sums bool) {
 			localConn, err := listener.AcceptSocks()
 			if err != nil {
 				if e, ok := err.(net.Error); ok && e.Temporary() {
-					fmt.Printf("disruptor proxy temporary accept error: %s", err)
+					fmt.Printf("disruptor proxy temporary accept error: %s\n", err)
 					continue
 				}
 				fmt.Printf("disruptor proxy accept error: %s\n", err)