Преглед изворни кода

Fix: check memory spans in use, not virtual address space

- Go 1.11 allocates more virtual address space than
  previous versions (see golang issue 28114), but this
  does not necessarily impact the resident size, which
  we are testing for here, approximately.
Rod Hynes пре 7 година
родитељ
комит
03d870c3b4
1 измењених фајлова са 6 додато и 5 уклоњено
  1. 6 5
      psiphon/memory_test/memory_test.go

+ 6 - 5
psiphon/memory_test/memory_test.go

@@ -148,7 +148,7 @@ func runMemoryTest(t *testing.T, testMode int) {
 	postActiveTunnelTerminateDelay := 250 * time.Millisecond
 	testDuration := 2 * time.Minute
 	memInspectionFrequency := 10 * time.Second
-	maxSysMemory := uint64(11 * 1024 * 1024)
+	maxInuseBytes := uint64(10 * 1024 * 1024)
 
 	psiphon.SetNoticeWriter(psiphon.NewNoticeReceiver(
 		func(notice []byte) {
@@ -229,12 +229,13 @@ test_loop:
 		case <-memInspectionTicker.C:
 			var m runtime.MemStats
 			runtime.ReadMemStats(&m)
-			if m.Sys > maxSysMemory {
-				t.Fatalf("sys memory exceeds limit: %d", m.Sys)
+			inuseBytes := m.HeapInuse + m.StackInuse + m.MSpanInuse + m.MCacheInuse
+			if inuseBytes > maxInuseBytes {
+				t.Fatalf("MemStats.*Inuse bytes exceeds limit: %d", inuseBytes)
 			} else {
 				n := atomic.LoadInt32(&tunnelsEstablished)
-				fmt.Printf("Tunnels established: %d, MemStats.Sys (peak system memory used): %s, MemStats.TotalAlloc (cumulative allocations): %s\n",
-					n, common.FormatByteCount(m.Sys), common.FormatByteCount(m.TotalAlloc))
+				fmt.Printf("Tunnels established: %d, MemStats.*InUse (peak memory in use): %s, MemStats.TotalAlloc (cumulative allocations): %s\n",
+					n, common.FormatByteCount(inuseBytes), common.FormatByteCount(m.TotalAlloc))
 				if lastTunnelsEstablished-n >= 0 {
 					t.Fatalf("expected established tunnels")
 				}