Skip to content
Open
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
17 changes: 17 additions & 0 deletions cmd/modern/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"
"sync"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -312,6 +313,22 @@ func TestE2E_PipedInput_WithBytesBuffer_NoPanic(t *testing.T) {
assert.NotContains(t, outputStr, "nil pointer", "should not have nil pointer error")
}

func TestE2E_QueryTimeout_NoHang(t *testing.T) {
skipIfNoLiveConnection(t)
binary := buildBinary(t)

args := append([]string{"-C", "-t", "1", "-Q", "WAITFOR DELAY '00:00:10'"}, getAuthArgs(t)...)
cmd := exec.Command(binary, args...)
cmd.Env = os.Environ()

start := time.Now()
output, _ := cmd.CombinedOutput()
elapsed := time.Since(start)

assert.Contains(t, string(output), "Timeout expired")
assert.Less(t, elapsed, 30*time.Second, "command hung instead of timing out")
}

// cleanupBinary removes the temporary build directory containing the test binary.
// TestMain calls this to ensure deterministic cleanup instead of relying on
// eventual OS temp directory maintenance.
Expand Down
3 changes: 3 additions & 0 deletions pkg/sqlcmd/sqlcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@ func (s *Sqlcmd) runQuery(query string) (int, error) {
}
retmsg := &sqlexp.ReturnMessage{}
rows, qe := s.db.QueryContext(ctx, query, retmsg)
if rows != nil {
defer func() { _ = rows.Close() }()
}
if qe != nil {
s.Format.AddError(qe)
}
Expand Down
Loading