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 exec test on windows #519

Merged
merged 1 commit into from
Aug 31, 2019
Merged
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
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