Skip to content

Commit d157534

Browse files
- Async pprogress messages now routed to stderr, prior case was stdout.
1 parent 2e546e9 commit d157534

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed

internal/stackql/driver/dependent_simple_integration_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestSimpleInsertDependentGoogleComputeDiskAsync(t *testing.T) {
3838
if err != nil {
3939
t.Fatalf("Test failed: %v", err)
4040
}
41-
handlerCtx, err := entryutil.BuildHandlerContext(*runtimeCtx, rdr, lrucache.NewLRUCache(int64(runtimeCtx.QueryCacheSize)), inputBundle.WithStdOut(outFile), true)
41+
handlerCtx, err := entryutil.BuildHandlerContext(*runtimeCtx, rdr, lrucache.NewLRUCache(int64(runtimeCtx.QueryCacheSize)), inputBundle.WithStdErr(outFile), true)
4242
if err != nil {
4343
t.Fatalf("Test failed: %v", err)
4444
}
@@ -76,7 +76,7 @@ func TestSimpleInsertDependentGoogleComputeDiskAsyncReversed(t *testing.T) {
7676
if err != nil {
7777
t.Fatalf("Test failed: %v", err)
7878
}
79-
handlerCtx, err := entryutil.BuildHandlerContext(*runtimeCtx, rdr, lrucache.NewLRUCache(int64(runtimeCtx.QueryCacheSize)), inputBundle.WithStdOut(outFile), true)
79+
handlerCtx, err := entryutil.BuildHandlerContext(*runtimeCtx, rdr, lrucache.NewLRUCache(int64(runtimeCtx.QueryCacheSize)), inputBundle.WithStdErr(outFile), true)
8080
if err != nil {
8181
t.Fatalf("Test failed: %v", err)
8282
}

internal/stackql/driver/driver_integration_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func TestSimpleInsertGoogleComputeNetworkAsync(t *testing.T) {
180180
}
181181

182182
testSubject := func(t *testing.T, outFile *bufio.Writer) {
183-
handlerCtx, err := entryutil.BuildHandlerContext(*runtimeCtx, strings.NewReader(""), lrucache.NewLRUCache(int64(runtimeCtx.QueryCacheSize)), inputBundle.WithStdOut(outFile), true)
183+
handlerCtx, err := entryutil.BuildHandlerContext(*runtimeCtx, strings.NewReader(""), lrucache.NewLRUCache(int64(runtimeCtx.QueryCacheSize)), inputBundle.WithStdErr(outFile), true)
184184
if err != nil {
185185
t.Fatalf("Test failed: %v", err)
186186
}
@@ -226,7 +226,7 @@ func TestK8sTheHardWayAsync(t *testing.T) {
226226
runtimeCtx.InfilePath = k8sthwRenderedFile
227227
runtimeCtx.CSVHeadersDisable = true
228228

229-
handlerCtx, err := entryutil.BuildHandlerContext(*runtimeCtx, strings.NewReader(""), lrucache.NewLRUCache(int64(runtimeCtx.QueryCacheSize)), inputBundle.WithStdOut(outFile), true)
229+
handlerCtx, err := entryutil.BuildHandlerContext(*runtimeCtx, strings.NewReader(""), lrucache.NewLRUCache(int64(runtimeCtx.QueryCacheSize)), inputBundle.WithStdErr(outFile), true)
230230
if err != nil {
231231
t.Fatalf("Test failed: %v", err)
232232
}

internal/stackql/execution/mono_valent_execution.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,7 @@ func GetMonitorExecutor(
16201620
asyncPrim.elapsedSeconds += asyncPrim.pollIntervalSeconds
16211621
if !asyncPrim.noStatus {
16221622
//nolint:errcheck //TODO: handle error
1623-
pc.GetWriter().Write(
1623+
pc.GetErrWriter().Write(
16241624
[]byte(
16251625
fmt.Sprintf(
16261626
"%s in progress, %d seconds elapsed",
@@ -1862,7 +1862,7 @@ func prepareResultSet(
18621862
}
18631863
if !prim.noStatus {
18641864
//nolint:errcheck //TODO: handle error
1865-
pc.GetWriter().Write([]byte(fmt.Sprintf("%s complete", operationDescriptor) + fmt.Sprintln("")))
1865+
pc.GetErrWriter().Write([]byte(fmt.Sprintf("%s complete", operationDescriptor) + fmt.Sprintln("")))
18661866
}
18671867
return util.PrepareResultSet(payload)
18681868
}

internal/test/stackqltestutil/helper.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,28 @@ func RunStdOutTestAgainstFiles(t *testing.T, testSubject func(*testing.T), possi
3333
checkPossibleMatchFiles(t, out, possibleExpectedOutputFiles)
3434
}
3535

36+
func RunStdErrTestAgainstFiles(t *testing.T, testSubject func(*testing.T), possibleExpectedOutputFiles []string) {
37+
old := os.Stderr // keep backup of the real stderr
38+
r, w, _ := os.Pipe()
39+
os.Stderr = w
40+
outC := make(chan string)
41+
42+
testSubject(t)
43+
44+
// copy the output in a separate goroutine so printing can't block indefinitely
45+
go func() {
46+
var buf bytes.Buffer
47+
io.Copy(&buf, r) //nolint:errcheck // ok for testing
48+
outC <- buf.String()
49+
}()
50+
w.Close()
51+
os.Stderr = old // restoring the real stderr
52+
out := <-outC
53+
t.Logf("outC = %s", out)
54+
55+
checkPossibleMatchFiles(t, out, possibleExpectedOutputFiles)
56+
}
57+
3658
func checkPossibleMatchFiles(t *testing.T, subject string, possibleExpectedOutputFiles []string) {
3759
hasMatchedExpected := false
3860
for _, expectedOpFile := range possibleExpectedOutputFiles {

stackql/main_integration_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func TestK8STemplatedE2eSuccess(t *testing.T) {
7979

8080
os.Args = args
8181

82-
stackqltestutil.RunStdOutTestAgainstFiles(t, execStuff, []string{testobjects.ExpectedK8STheHardWayAsyncFile})
82+
stackqltestutil.RunStdErrTestAgainstFiles(t, execStuff, []string{testobjects.ExpectedK8STheHardWayAsyncFile})
8383
}
8484

8585
func TestInsertAwaitExecSuccess(t *testing.T) {
@@ -105,7 +105,7 @@ func TestInsertAwaitExecSuccess(t *testing.T) {
105105

106106
os.Args = args
107107

108-
stackqltestutil.RunStdOutTestAgainstFiles(t, execStuff, []string{testobjects.ExpectedComputeNetworkInsertAsyncFile})
108+
stackqltestutil.RunStdErrTestAgainstFiles(t, execStuff, []string{testobjects.ExpectedComputeNetworkInsertAsyncFile})
109109
}
110110

111111
func TestDeleteAwaitSuccess(t *testing.T) {
@@ -130,7 +130,7 @@ func TestDeleteAwaitSuccess(t *testing.T) {
130130

131131
os.Args = args
132132

133-
stackqltestutil.RunStdOutTestAgainstFiles(t, execStuff, []string{testobjects.ExpectedComputeNetworkDeleteAsyncFile})
133+
stackqltestutil.RunStdErrTestAgainstFiles(t, execStuff, []string{testobjects.ExpectedComputeNetworkDeleteAsyncFile})
134134
}
135135

136136
func TestDeleteAwaitExecSuccess(t *testing.T) {
@@ -156,7 +156,7 @@ func TestDeleteAwaitExecSuccess(t *testing.T) {
156156

157157
os.Args = args
158158

159-
stackqltestutil.RunStdOutTestAgainstFiles(t, execStuff, []string{testobjects.ExpectedComputeNetworkDeleteAsyncFile})
159+
stackqltestutil.RunStdErrTestAgainstFiles(t, execStuff, []string{testobjects.ExpectedComputeNetworkDeleteAsyncFile})
160160
}
161161

162162
func execStuff(t *testing.T) {

0 commit comments

Comments
 (0)