Merge pull request #12773 from ptabor/20210310-test-fixes

Minor test fixes
This commit is contained in:
Piotr Tabor 2021-03-14 13:36:19 +01:00 committed by GitHub
commit 527c765ece
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

View File

@ -80,7 +80,7 @@ func TestDialCancel(t *testing.T) {
}
func TestDialTimeout(t *testing.T) {
defer testutil.AfterTest(t)
testutil.BeforeTest(t)
wantError := context.DeadlineExceeded

View File

@ -29,6 +29,8 @@ import (
"github.com/creack/pty"
)
const DEBUG_LINES_TAIL = 40
type ExpectProcess struct {
cmd *exec.Cmd
fpty *os.File
@ -96,6 +98,8 @@ func (ep *ExpectProcess) read() {
// ExpectFunc returns the first line satisfying the function f.
func (ep *ExpectProcess) ExpectFunc(f func(string) bool) (string, error) {
lastLinesBuffer := make([]string, 0)
ep.mu.Lock()
for {
for len(ep.lines) == 0 && ep.err == nil {
@ -106,13 +110,19 @@ func (ep *ExpectProcess) ExpectFunc(f func(string) bool) (string, error) {
}
l := ep.lines[0]
ep.lines = ep.lines[1:]
lastLinesBuffer = append(lastLinesBuffer, l)
if l := len(lastLinesBuffer); l > DEBUG_LINES_TAIL {
lastLinesBuffer = lastLinesBuffer[l-DEBUG_LINES_TAIL : l-1]
}
if f(l) {
ep.mu.Unlock()
return l, nil
}
}
ep.mu.Unlock()
return "", ep.err
return "", fmt.Errorf("Match not found."+
" Set EXPECT_DEBUG for more info Err: %v, last lines:\n%s\n\n",
ep.err, strings.Join(lastLinesBuffer, ""))
}
// Expect returns the first line containing the given string.

View File

@ -35,7 +35,7 @@ import (
// TestV3StorageQuotaApply tests the V3 server respects quotas during apply
func TestV3StorageQuotaApply(t *testing.T) {
testutil.AfterTest(t)
testutil.BeforeTest(t)
quotasize := int64(16 * os.Getpagesize())
clus := NewClusterV3(t, &ClusterConfig{Size: 2})