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

fix 1 race #1783

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
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
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.