Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workaround for captive core bug in integration tests #223

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions cmd/soroban-rpc/internal/integrationtest/infrastructure/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (i *Test) spawnContainers() {
i.runSuccessfulComposeCommand(upCmd...)
if i.runRPCInContainer() {
i.rpcContainerLogsCommand = i.getComposeCommand("logs", "--no-log-prefix", "-f", "rpc")
writer := testLogWriter{t: i.t, prefix: fmt.Sprintf(`rpc="container" version="%s" `, i.rpcContainerVersion)}
writer := newTestLogWriter(i.t, fmt.Sprintf(`rpc="container" version="%s" `, i.rpcContainerVersion))
i.rpcContainerLogsCommand.Stdout = writer
i.rpcContainerLogsCommand.Stderr = writer
require.NoError(i.t, i.rpcContainerLogsCommand.Start())
Expand Down Expand Up @@ -397,12 +397,34 @@ func (i *Test) generateRPCConfigFile(rpcConfig rpcConfig) {
require.NoError(i.t, err)
}

type testLogWriter struct {
t *testing.T
prefix string
func newTestLogWriter(t *testing.T, prefix string) *testLogWriter {
tw := &testLogWriter{t: t, prefix: prefix}
t.Cleanup(func() {
tw.testDoneMx.Lock()
tw.testDone = true
tw.testDoneMx.Unlock()
})
return tw
}

func (tw testLogWriter) Write(p []byte) (n int, err error) {
type testLogWriter struct {
t *testing.T
prefix string
testDoneMx sync.RWMutex
testDone bool
}

func (tw *testLogWriter) Write(p []byte) (n int, err error) {
tw.testDoneMx.RLock()
if tw.testDone {
// Workaround for https://github.com/stellar/go/issues/5342
// and https://github.com/stellar/go/issues/5350, which causes a race condition
// in test logging
// TODO: remove once the tickets are fixed
tw.testDoneMx.RUnlock()
return len(p), nil
}
tw.testDoneMx.RUnlock()
all := strings.TrimSpace(string(p))
lines := strings.Split(all, "\n")
for _, l := range lines {
Expand All @@ -423,7 +445,7 @@ func (i *Test) createRPCDaemon(c rpcConfig) *daemon.Daemon {
cfg.HistoryArchiveUserAgent = fmt.Sprintf("soroban-rpc/%s", config.Version)

logger := supportlog.New()
logger.SetOutput(testLogWriter{t: i.t, prefix: `rpc="daemon" `})
logger.SetOutput(newTestLogWriter(i.t, `rpc="daemon" `))
return daemon.MustNew(&cfg, logger)
}

Expand Down
Loading