Просмотр исходного кода

Fix tests
- Allow more time for GitHub Actions common/inproxy test runs
- Add missing TargetAPIEncoding case
- Fix expected client_bpf case
- Workaround race detector memory usage issue in TestSessions
- Fix missing test logger function

Rod Hynes 1 год назад
Родитель
Сommit
d5e20d447d

+ 3 - 3
.github/workflows/tests.yml

@@ -80,7 +80,7 @@ jobs:
           go test -v -race ./psiphon/common/accesscontrol
           go test -v -race ./psiphon/common/crypto/ssh
           go test -v -race ./psiphon/common/fragmentor
-          go test -v -race ./psiphon/common/inproxy
+          go test -v -timeout 20m -race ./psiphon/common/inproxy
           go test -v -race ./psiphon/common/regen
           go test -v -race ./psiphon/common/monotime
           go test -v -race ./psiphon/common/obfuscator
@@ -113,7 +113,7 @@ jobs:
           go test -v -covermode=count -coverprofile=accesscontrol.coverprofile ./psiphon/common/accesscontrol
           go test -v -covermode=count -coverprofile=ssh.coverprofile ./psiphon/common/crypto/ssh
           go test -v -covermode=count -coverprofile=fragmentor.coverprofile ./psiphon/common/fragmentor
-          go test -v -covermode=count -coverprofile=inproxy.coverprofile ./psiphon/common/inproxy
+          go test -v -timeout 20m -covermode=count -coverprofile=inproxy.coverprofile ./psiphon/common/inproxy
           go test -v -covermode=count -coverprofile=regen.coverprofile ./psiphon/common/regen
           go test -v -covermode=count -coverprofile=monotime.coverprofile ./psiphon/common/monotime
           go test -v -covermode=count -coverprofile=obfuscator.coverprofile ./psiphon/common/obfuscator
@@ -130,7 +130,7 @@ jobs:
           go test -v -covermode=count -coverprofile=transferstats.coverprofile ./psiphon/transferstats
           sudo -E env "PATH=$PATH" go test -v -timeout 20m -covermode=count -coverprofile=server.coverprofile -tags "PSIPHON_RUN_PACKET_MANIPULATOR_TEST" ./psiphon/server
           go test -v -covermode=count -coverprofile=psinet.coverprofile ./psiphon/server/psinet
-          go test -v -timeout 20m  -covermode=count -coverprofile=psiphon.coverprofile ./psiphon
+          go test -v -timeout 20m -covermode=count -coverprofile=psiphon.coverprofile ./psiphon
           go test -v -covermode=count -coverprofile=clientlib.coverprofile ./ClientLibrary/clientlib
           go test -v -covermode=count -coverprofile=analysis.coverprofile ./Server/logging/analysis
           $GOPATH/bin/gover

+ 7 - 0
psiphon/common/inproxy/session_test.go

@@ -28,6 +28,7 @@ import (
 	"testing"
 	"time"
 
+	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/errors"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/prng"
 	"github.com/flynn/noise"
@@ -288,6 +289,12 @@ func runTestSessions() error {
 	requestCount := 100
 	concurrentRequestCount := 5
 
+	if common.IsRaceDetectorEnabled {
+		// Workaround for very high memory usage and OOM that occurs only with
+		// the race detector enabled.
+		clientCount = 100
+	}
+
 	resultChan := make(chan error, clientCount)
 
 	for i := 0; i < clientCount; i++ {

+ 5 - 0
psiphon/common/packetman/packetman_linux_test.go

@@ -1,3 +1,4 @@
+//go:build PSIPHON_RUN_PACKET_MANIPULATOR_TEST
 // +build PSIPHON_RUN_PACKET_MANIPULATOR_TEST
 
 /*
@@ -177,6 +178,10 @@ func (logger *testLogger) WithTraceFields(fields common.LogFields) common.LogTra
 func (logger *testLogger) LogMetric(metric string, fields common.LogFields) {
 }
 
+func (logger *testLogger) IsLogLevelDebug() bool {
+	return true
+}
+
 type testLogTrace struct {
 	trace  string
 	fields common.LogFields

+ 25 - 0
psiphon/common/raceDetector_disabled.go

@@ -0,0 +1,25 @@
+//go:build !race
+// +build !race
+
+/*
+ * Copyright (c) 2024, Psiphon Inc.
+ * All rights reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package common
+
+const IsRaceDetectorEnabled = false

+ 25 - 0
psiphon/common/raceDetector_enabled.go

@@ -0,0 +1,25 @@
+//go:build race
+// +build race
+
+/*
+ * Copyright (c) 2024, Psiphon Inc.
+ * All rights reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package common
+
+const IsRaceDetectorEnabled = true

+ 5 - 0
psiphon/memory_test/memory_test.go

@@ -36,6 +36,7 @@ import (
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/parameters"
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/prng"
+	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/protocol"
 )
 
 // memory_test is a memory stress test suite that repeatedly reestablishes
@@ -109,6 +110,10 @@ func runMemoryTest(t *testing.T, testMode int) {
 	modifyConfig["StaggerConnectionWorkersMilliseconds"] = 100
 	modifyConfig["IgnoreHandshakeStatsRegexps"] = true
 
+	// Use the legacy encoding to both exercise that case, and facilitate a
+	// gradual network upgrade to new encoding support.
+	modifyConfig["TargetAPIEncoding"] = protocol.PSIPHON_API_ENCODING_JSON
+
 	configJSON, _ = json.Marshal(modifyConfig)
 
 	config, err := psiphon.LoadConfig(configJSON)

+ 1 - 1
psiphon/server/server_packetman_test.go

@@ -1,3 +1,4 @@
+//go:build PSIPHON_RUN_PACKET_MANIPULATOR_TEST
 // +build PSIPHON_RUN_PACKET_MANIPULATOR_TEST
 
 /*
@@ -29,7 +30,6 @@ func TestServerPacketManipulation(t *testing.T) {
 	runServer(t,
 		&runServerConfig{
 			tunnelProtocol:       "UNFRONTED-MEEK-SESSION-TICKET-OSSH",
-			enableSSHAPIRequests: true,
 			doHotReload:          false,
 			doDefaultSponsorID:   false,
 			denyTrafficRules:     false,

+ 2 - 1
psiphon/server/server_test.go

@@ -1635,7 +1635,8 @@ func runServer(t *testing.T, runConfig *runServerConfig) {
 	// without this delay.
 	time.Sleep(100 * time.Millisecond)
 
-	expectClientBPFField := psiphon.ClientBPFEnabled() && doClientTactics
+	// For in-proxy tunnel protocols, client BPF tactics are currently ignored and not applied by the 2nd hop.
+	expectClientBPFField := psiphon.ClientBPFEnabled() && doClientTactics && !protocol.TunnelProtocolUsesInproxy(runConfig.tunnelProtocol)
 	expectServerBPFField := ServerBPFEnabled() && protocol.TunnelProtocolIsDirect(runConfig.tunnelProtocol) && doServerTactics
 	expectServerPacketManipulationField := runConfig.doPacketManipulation
 	expectBurstFields := runConfig.doBurstMonitor