Skip to content

Commit

Permalink
Merge pull request #1783 from alixander/fix-race
Browse files Browse the repository at this point in the history
fix 1 race
  • Loading branch information
alixander authored Dec 19, 2023
2 parents 6882aac + e711b97 commit fa98423
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 9 deletions.
26 changes: 26 additions & 0 deletions e2etests-cli/concurrent_buf.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package e2etests_cli

import "sync"

// stderrWrapper lets stderr be read/write concurrently
type stderrWrapper struct {
msg string
m sync.Mutex
}

func (e *stderrWrapper) Write(p []byte) (n int, err error) {
e.m.Lock()
defer e.m.Unlock()
e.msg += string(p)
return len(p), nil
}

func (e *stderrWrapper) Reset() {
e.msg = ""
}

func (e *stderrWrapper) Read() string {
e.m.Lock()
defer e.m.Unlock()
return e.msg
}
18 changes: 9 additions & 9 deletions e2etests-cli/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ layers: {
c -> b
}
}`)
stderr := &bytes.Buffer{}
stderr := &stderrWrapper{}
tms := testMain(dir, env, "--watch", "--browser=0", "index.d2")
tms.Stderr = stderr

Expand Down Expand Up @@ -935,7 +935,7 @@ layers: {
c -> b
}
}`)
stderr := &bytes.Buffer{}
stderr := &stderrWrapper{}
tms := testMain(dir, env, "--watch", "--browser=0", "index.d2")
tms.Stderr = stderr

Expand Down Expand Up @@ -988,7 +988,7 @@ layers: {
c -> b
}
}`)
stderr := &bytes.Buffer{}
stderr := &stderrWrapper{}
tms := testMain(dir, env, "--watch", "--browser=0", "index.d2")
tms.Stderr = stderr

Expand Down Expand Up @@ -1036,7 +1036,7 @@ layers: {
writeFile(t, dir, "b.d2", `
x
`)
stderr := &bytes.Buffer{}
stderr := &stderrWrapper{}
tms := testMain(dir, env, "--watch", "--browser=0", "a.d2")
tms.Stderr = stderr

Expand Down Expand Up @@ -1202,26 +1202,26 @@ func getNumBoards(svg string) int {

var errRE = regexp.MustCompile(`err:`)

func waitLogs(ctx context.Context, buf *bytes.Buffer, pattern *regexp.Regexp) (string, error) {
func waitLogs(ctx context.Context, stream *stderrWrapper, pattern *regexp.Regexp) (string, error) {
ticker := time.NewTicker(10 * time.Millisecond)
defer ticker.Stop()
var match string
for i := 0; i < 1000 && match == ""; i++ {
select {
case <-ticker.C:
out := buf.String()
out := stream.Read()
match = pattern.FindString(out)
errMatch := errRE.FindString(out)
if errMatch != "" {
return "", errors.New(buf.String())
return "", errors.New(out)
}
case <-ctx.Done():
ticker.Stop()
return "", fmt.Errorf("could not match pattern in log. logs: %s", buf.String())
return "", fmt.Errorf("could not match pattern in log. logs: %s", stream.Read())
}
}
if match == "" {
return "", errors.New(buf.String())
return "", errors.New(stream.Read())
}

return match, nil
Expand Down
Binary file modified e2etests-cli/testdata/TestCLI_E2E/internal_linked_pdf.exp.pdf
Binary file not shown.
Binary file modified e2etests-cli/testdata/TestCLI_E2E/no-nav-pdf.exp.pdf
Binary file not shown.
Binary file modified e2etests-cli/testdata/TestCLI_E2E/no-nav-pptx.exp.pptx
Binary file not shown.
Binary file modified e2etests-cli/testdata/TestCLI_E2E/renamed-board.exp.pdf
Binary file not shown.

0 comments on commit fa98423

Please sign in to comment.