aboutsummaryrefslogtreecommitdiff
path: root/awwan_play_test.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2026-02-15 13:03:38 +0700
committerShulhan <ms@kilabit.info>2026-02-15 13:37:31 +0700
commit19d58e9a4c900aec1d63de45a655657c760b1235 (patch)
tree959af0093d9ed2aca4976c69deb25a2d48fca44b /awwan_play_test.go
parent827a2741e4fcb8e6feb5bf76acb20799c2913451 (diff)
downloadawwan-19d58e9a4c900aec1d63de45a655657c760b1235.tar.xz
all: fix data race in Play and in integration tests
When the Play command executed from the web user interface, there is a possibility that concurrent requests set the sshConfig field in Awwan struct at the same time. In the integration tests for TestAwwan_Play_withLocal and TestExecLocal_sudo, the data race happens when writing to the same buffer for stdout and stderr, so we split them into separate buffers. There is also data race in SSE connection, when handler for ExecuteTail write to the same buffer with worker keep alive. This has been fixed on pakakeh.go module.
Diffstat (limited to 'awwan_play_test.go')
-rw-r--r--awwan_play_test.go33
1 files changed, 18 insertions, 15 deletions
diff --git a/awwan_play_test.go b/awwan_play_test.go
index 00d407d..4ae0cfc 100644
--- a/awwan_play_test.go
+++ b/awwan_play_test.go
@@ -13,6 +13,7 @@ import (
"path/filepath"
"testing"
+ "git.sr.ht/~shulhan/pakakeh.go/lib/mlog"
"git.sr.ht/~shulhan/pakakeh.go/lib/test"
)
@@ -33,7 +34,8 @@ func TestAwwan_Play_withLocal(t *testing.T) {
type testCase struct {
scriptFile string
lineRange string
- expOutput string
+ expStdout string
+ expStderr string
expError string
}
@@ -60,37 +62,38 @@ func TestAwwan_Play_withLocal(t *testing.T) {
var cases = []testCase{{
scriptFile: filepath.Join(scriptDir, `play.aww`),
lineRange: `1-`,
- expOutput: string(tdata.Output[`play_with_local:output`]),
+ expStdout: string(tdata.Output[`play_with_local:stdout`]),
+ expStderr: string(tdata.Output[`play_with_local:stderr`]),
}, {
scriptFile: filepath.Join(scriptDir, `tmp`),
expError: `NewExecRequest: "testdata/play/awwanssh.test/tmp" is a directory`,
}}
- var (
- ctx = context.Background()
-
- c testCase
- req *ExecRequest
- logw bytes.Buffer
- )
+ var testerr bytes.Buffer
+ var namederr = mlog.NewNamedWriter(`testerr`, &testerr)
+ var testout bytes.Buffer
+ var namedout = mlog.NewNamedWriter(`testout`, &testout)
- for _, c = range cases {
- req, err = NewExecRequest(CommandModePlay, c.scriptFile, c.lineRange)
+ for _, c := range cases {
+ req, err := NewExecRequest(CommandModePlay, c.scriptFile, c.lineRange)
if err != nil {
test.Assert(t, `NewExecRequest: error`, c.expError, err.Error())
continue
}
- logw.Reset()
- req.registerLogWriter(`output`, &logw)
+ testerr.Reset()
+ testout.Reset()
+ req.mlog.RegisterErrorWriter(namederr)
+ req.mlog.RegisterOutputWriter(namedout)
- err = aww.Play(ctx, req)
+ err = aww.Play(context.Background(), req)
if err != nil {
test.Assert(t, `Play: error`, c.expError, err.Error())
continue
}
- test.Assert(t, `Local`, c.expOutput, logw.String())
+ test.Assert(t, `stdout`, c.expStdout, testout.String())
+ test.Assert(t, `stderr`, c.expStderr, testerr.String())
}
}