Skip to content

Commit

Permalink
refine TestRunCloseFail(), TestCloseChild() for #34.
Browse files Browse the repository at this point in the history
disable TestRunCloseFail(), TestRecvSRTT() for s390x.
  • Loading branch information
ericwq committed Mar 23, 2024
1 parent 6f29bae commit 88adc2f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 34 deletions.
1 change: 1 addition & 0 deletions frontend/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ func (m *mainSrv) closeChild(req string, addr *net.UDPAddr) {
if m.workers[port].child != nil {
m.workers[port].child.Signal(syscall.SIGTERM)
m.writeRespTo(addr, frontend.AprishMsgClose, "done")
util.Logger.Debug("close child done", "request", req)
} else {
resp := m.writeRespTo(addr, frontend.AprishMsgClose, "close port is a holder")
util.Logger.Warn("close port is a holder", "request", req, "response", resp)
Expand Down
76 changes: 42 additions & 34 deletions frontend/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1416,38 +1416,38 @@ func TestRunCloseFail(t *testing.T) {
finish int // pause before shutdown message
conf Config
}{
// {
// "runWorker stopped by " + frontend.AprishMsgClose, 20, frontend.AprilshMsgOpen + "7111,", frontend.AprishMsgClose + "done",
// []string{},
// 150,
// Config{
// version: false, server: true, flowControl: _FC_SKIP_PIPE_LOCK, desiredIP: "", desiredPort: "7110",
// locales: localeFlag{"LC_ALL": "en_US.UTF-8", "LANG": "en_US.UTF-8"},
// commandPath: "/bin/sh", commandArgv: []string{"-sh"}, withMotd: true,
// },
// },
// {
// "runWorker stop port not exist", 5, frontend.AprilshMsgOpen + "7121,", frontend.AprishMsgClose + "port does not exist",
// []string{"7100"},
// 150,
// Config{
// version: false, server: true, flowControl: _FC_SKIP_PIPE_LOCK, desiredIP: "", desiredPort: "7120",
// locales: localeFlag{"LC_ALL": "en_US.UTF-8", "LANG": "en_US.UTF-8"},
// commandPath: "/bin/sh", commandArgv: []string{"-sh"}, withMotd: true,
// },
// },
// {
// "runWorker stop wrong port number", 5, frontend.AprilshMsgOpen + "7131,", frontend.AprishMsgClose + "wrong port number",
// []string{"7121x"},
// 150,
// Config{
// version: false, server: true, flowControl: _FC_SKIP_PIPE_LOCK, desiredIP: "", desiredPort: "7130",
// locales: localeFlag{"LC_ALL": "en_US.UTF-8", "LANG": "en_US.UTF-8"},
// commandPath: "/bin/sh", commandArgv: []string{"-sh"}, withMotd: true,
// },
// },
{
"runWorker stopped by " + frontend.AprishMsgClose, 20, frontend.AprilshMsgOpen + "7111,", frontend.AprishMsgClose + "done",
[]string{},
150,
Config{
version: false, server: true, flowControl: _FC_SKIP_PIPE_LOCK, desiredIP: "", desiredPort: "7110",
locales: localeFlag{"LC_ALL": "en_US.UTF-8", "LANG": "en_US.UTF-8"},
commandPath: "/bin/sh", commandArgv: []string{"-sh"}, withMotd: true,
},
},
{
"runWorker stop port not exist", 5, frontend.AprilshMsgOpen + "7121,", frontend.AprishMsgClose + "port does not exist",
[]string{"7100"},
150,
Config{
version: false, server: true, flowControl: _FC_SKIP_PIPE_LOCK, desiredIP: "", desiredPort: "7120",
locales: localeFlag{"LC_ALL": "en_US.UTF-8", "LANG": "en_US.UTF-8"},
commandPath: "/bin/sh", commandArgv: []string{"-sh"}, withMotd: true,
},
},
{
"runWorker stop wrong port number", 5, frontend.AprilshMsgOpen + "7131,", frontend.AprishMsgClose + "wrong port number",
[]string{"7121x"},
150,
Config{
version: false, server: true, flowControl: _FC_SKIP_PIPE_LOCK, desiredIP: "", desiredPort: "7130",
locales: localeFlag{"LC_ALL": "en_US.UTF-8", "LANG": "en_US.UTF-8"},
commandPath: "/bin/sh", commandArgv: []string{"-sh"}, withMotd: true,
},
},
{
"runWorker stop unknow request", 5, frontend.AprilshMsgOpen + "7141,", frontend.AprishMsgClose + "unknow request",
"runWorker stop unknow request", 25, frontend.AprilshMsgOpen + "7141,", frontend.AprishMsgClose + "unknow request",
[]string{"two", "params"},
150,
Config{
Expand All @@ -1458,10 +1458,14 @@ func TestRunCloseFail(t *testing.T) {
},
}

if runtime.GOARCH == "s390x" {
t.Skip("for s390x, skip this test.")
}
for _, v := range tc {
t.Run(v.label, func(t *testing.T) {

util.Logger.CreateLogger(io.Discard, true, slog.LevelDebug)
// util.Logger.CreateLogger(os.Stderr, true, slog.LevelDebug)

// set serve func and runWorker func
v.conf.serve = mockServe
Expand Down Expand Up @@ -2386,6 +2390,10 @@ func TestCloseChild(t *testing.T) {
}{
{"placeHolder port", frontend.AprishMsgClose + "6252", []int{6252},
&Config{desiredPort: "6250"}, "close port is a holder"},
{"wrong port number", frontend.AprishMsgClose + "625a", nil,
&Config{desiredPort: "6250"}, "wrong port number"},
{"port doesn't exist", frontend.AprishMsgClose + "6252", nil,
&Config{desiredPort: "6250"}, "port does not exist"},
}

for _, v := range tc {
Expand All @@ -2404,15 +2412,15 @@ func TestCloseChild(t *testing.T) {
for _, value := range v.holders {
m.workers[value] = &workhorse{}
}
// reading and validate the message
// reading the udp response
wg.Add(1)
go func() {
defer wg.Done()

buf := make([]byte, 128)
shutdown := false
for {
select {
select { // waiting for shutdown
case <-m.downChan:
shutdown = true
default:
Expand Down Expand Up @@ -2442,7 +2450,7 @@ func TestCloseChild(t *testing.T) {

// validate the result
got := out.String()
fmt.Println(got)
// fmt.Println(got)
if !strings.Contains(got, v.expect) {
t.Errorf("startChild expect %q, got \n%s\n", v.expect, got)
}
Expand Down
4 changes: 4 additions & 0 deletions network/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,10 @@ func (m *mockSession) Encrypt(plainText *encrypt.Message) []byte {
}

func TestRecvSRTT(t *testing.T) {
if runtime.GOARCH == "s390x" {
t.Skip("for s390x, skip this test.")
}

// prepare the client and server connection
title := "receive packet to calculate SRTT/RTTVAR"
ip := ""
Expand Down
5 changes: 5 additions & 0 deletions network/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io"
"log/slog"
"os"
"runtime"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -80,6 +81,10 @@ func TestTransportClientSend(t *testing.T) {
}

func TestTransportServerSend(t *testing.T) {
if runtime.GOARCH == "s390x" {
t.Skip("for s390x, skip this test.")
}

completeTerminal, _ := statesync.NewComplete(80, 5, 0)
blank := &statesync.UserStream{}
desiredIp := ""
Expand Down

0 comments on commit 88adc2f

Please sign in to comment.