Add trailing slash to directory to produce completions for (#1666)

## Changes

The integration test for `fs ls` tried to produce completions for the
temporary directory without a trailing slash. The command will list the
parent directory to see if there are more directories with the same
prefix that are also valid completions. The test intends to test
completions for files inside the temporary directory, so we need that
trailing slash.

This test was hanging because the parent directory of the temporary DBFS
directory has more than 1k entries (on our integration testing
workspaces) and the line buffer in the test runner has a capacity of 1k
lines. To avoid the same hang in the future, this change modifies the
test runner to panic if the line buffer is full.

## Tests

Confirmed the integration test no longer hangs.
This commit is contained in:
Pieter Noordhuis 2024-08-12 09:07:50 +02:00 committed by GitHub
parent a240be0b5a
commit 0a4c0fb588
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View File

@ -21,7 +21,7 @@ func TestAccFsCompletion(t *testing.T) {
f, tmpDir := setupDbfsFiler(t) f, tmpDir := setupDbfsFiler(t)
setupCompletionFile(t, f) setupCompletionFile(t, f)
stdout, _ := RequireSuccessfulRun(t, "__complete", "fs", "ls", tmpDir) stdout, _ := RequireSuccessfulRun(t, "__complete", "fs", "ls", tmpDir+"/")
expectedOutput := fmt.Sprintf("%s/dir1/\n:2\n", tmpDir) expectedOutput := fmt.Sprintf("%s/dir1/\n:2\n", tmpDir)
assert.Equal(t, expectedOutput, stdout.String()) assert.Equal(t, expectedOutput, stdout.String())
} }

View File

@ -94,10 +94,16 @@ func consumeLines(ctx context.Context, wg *sync.WaitGroup, r io.Reader) <-chan s
defer wg.Done() defer wg.Done()
scanner := bufio.NewScanner(r) scanner := bufio.NewScanner(r)
for scanner.Scan() { for scanner.Scan() {
// We expect to be able to always send these lines into the channel.
// If we can't, it means the channel is full and likely there is a problem
// in either the test or the code under test.
select { select {
case <-ctx.Done(): case <-ctx.Done():
return return
case ch <- scanner.Text(): case ch <- scanner.Text():
continue
default:
panic("line buffer is full")
} }
} }
}() }()