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

test: fix autoclient flakiness #9769

Merged
merged 1 commit into from
Mar 29, 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
1 change: 1 addition & 0 deletions test/cli/dht_autoclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestDHTAutoclient(t *testing.T) {
t.Run("file added on node in client mode is retrievable from node in client mode", func(t *testing.T) {
t.Parallel()
randomBytes := testutils.RandomBytes(1000)
randomBytes = append(randomBytes, '\r')
hash := nodes[8].IPFSAdd(bytes.NewReader(randomBytes))

res := nodes[9].IPFS("cat", hash)
Expand Down
12 changes: 10 additions & 2 deletions test/cli/harness/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,19 @@ func (b *Buffer) String() string {
return b.b.String()
}

// Trimmed returns the bytes as a string, with leading and trailing whitespace removed.
// Trimmed returns the bytes as a string, but with the trailing newline removed.
// This only removes a single trailing newline, not all whitespace.
func (b *Buffer) Trimmed() string {
b.m.Lock()
defer b.m.Unlock()
return strings.TrimSpace(b.b.String())
s := b.b.String()
if len(s) == 0 {
return s
}
if s[len(s)-1] == '\n' {
return s[:len(s)-1]
}
return s
}

func (b *Buffer) Bytes() []byte {
Expand Down