Skip to content

Commit

Permalink
Merge pull request #519 from Random-Liu/fix-exec-test
Browse files Browse the repository at this point in the history
Fix exec test on windows
  • Loading branch information
k8s-ci-robot authored Aug 31, 2019
2 parents 3df3f02 + 847f73b commit 8c8c91c
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions pkg/validate/streaming.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import (
. "github.com/onsi/gomega"
)

const defaultExecStdinCloseTimeout = 20 * time.Second

var _ = framework.KubeDescribe("Streaming", func() {
f := framework.NewDefaultCRIFramework()

Expand Down Expand Up @@ -175,23 +177,29 @@ func createExec(c internalapi.RuntimeService, execReq *runtimeapi.ExecRequest) s
}

func checkExec(c internalapi.RuntimeService, execServerURL, stdout string, stdoutExactMatch bool, isTty bool) {
localOut := &safeBuffer{buffer: bytes.Buffer{}}
localErr := &safeBuffer{buffer: bytes.Buffer{}}
localInRead, localInWrite := io.Pipe()

var (
localOut = &safeBuffer{buffer: bytes.Buffer{}}
localErr = &safeBuffer{buffer: bytes.Buffer{}}
localInRead, localInWrite = io.Pipe()
testDone = make(chan struct{})
wg sync.WaitGroup
)

wg.Add(1)
// Wait until output read and then shutdown localIn pipe.
go func() {
ticker := time.NewTicker(5 * time.Second)
for {
switch {
case len(localOut.String()) >= len(stdout):
fallthrough
case <-ticker.C != time.Time{}:
localInWrite.Close()
break
}
defer wg.Done()
defer localInWrite.Close()
ticker := time.NewTicker(defaultExecStdinCloseTimeout)
select {
case <-testDone:
case <-ticker.C:
}
}()
defer func() {
close(testDone)
wg.Wait()
}()

// Only http is supported now.
// TODO: support streaming APIs via tls.
Expand Down

0 comments on commit 8c8c91c

Please sign in to comment.