chore: avoid concurrent usage of t.FailNow (#1683)

* chore: golangci: add linter rule to report usage of t.FailNow inside goroutines
* chore: avoid t.FailNow in goroutines to appease the race detector
This commit is contained in:
Cian Johnston
2022-05-24 08:58:39 +01:00
committed by GitHub
parent 9b70a9b2eb
commit c2f74f3cc2
27 changed files with 120 additions and 74 deletions
+2 -2
View File
@@ -6,7 +6,7 @@ import (
"time"
"github.com/spf13/cobra"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/assert"
"go.uber.org/atomic"
"github.com/coder/coder/cli/cliui"
@@ -43,7 +43,7 @@ func TestAgent(t *testing.T) {
go func() {
defer close(done)
err := cmd.Execute()
require.NoError(t, err)
assert.NoError(t, err)
}()
ptty.ExpectMatch("lost connection")
disconnected.Store(true)
+7 -6
View File
@@ -10,6 +10,7 @@ import (
"time"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/coder/coder/cli/cliui"
@@ -27,7 +28,7 @@ func TestPrompt(t *testing.T) {
resp, err := newPrompt(ptty, cliui.PromptOptions{
Text: "Example",
}, nil)
require.NoError(t, err)
assert.NoError(t, err)
msgChan <- resp
}()
ptty.ExpectMatch("Example")
@@ -44,7 +45,7 @@ func TestPrompt(t *testing.T) {
Text: "Example",
IsConfirm: true,
}, nil)
require.NoError(t, err)
assert.NoError(t, err)
doneChan <- resp
}()
ptty.ExpectMatch("Example")
@@ -80,7 +81,7 @@ func TestPrompt(t *testing.T) {
cliui.AllowSkipPrompt(cmd)
cmd.SetArgs([]string{"-y"})
})
require.NoError(t, err)
assert.NoError(t, err)
doneChan <- resp
}()
@@ -101,7 +102,7 @@ func TestPrompt(t *testing.T) {
resp, err := newPrompt(ptty, cliui.PromptOptions{
Text: "Example",
}, nil)
require.NoError(t, err)
assert.NoError(t, err)
doneChan <- resp
}()
ptty.ExpectMatch("Example")
@@ -117,7 +118,7 @@ func TestPrompt(t *testing.T) {
resp, err := newPrompt(ptty, cliui.PromptOptions{
Text: "Example",
}, nil)
require.NoError(t, err)
assert.NoError(t, err)
doneChan <- resp
}()
ptty.ExpectMatch("Example")
@@ -133,7 +134,7 @@ func TestPrompt(t *testing.T) {
resp, err := newPrompt(ptty, cliui.PromptOptions{
Text: "Example",
}, nil)
require.NoError(t, err)
assert.NoError(t, err)
doneChan <- resp
}()
ptty.ExpectMatch("Example")
+4 -4
View File
@@ -9,7 +9,7 @@ import (
"time"
"github.com/spf13/cobra"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/assert"
"github.com/coder/coder/cli/cliui"
"github.com/coder/coder/coderd/database"
@@ -90,9 +90,9 @@ func TestProvisionerJob(t *testing.T) {
go func() {
<-test.Next
currentProcess, err := os.FindProcess(os.Getpid())
require.NoError(t, err)
assert.NoError(t, err)
err = currentProcess.Signal(os.Interrupt)
require.NoError(t, err)
assert.NoError(t, err)
<-test.Next
test.JobMutex.Lock()
test.Job.Status = codersdk.ProvisionerJobCanceled
@@ -150,7 +150,7 @@ func newProvisionerJob(t *testing.T) provisionerJobTest {
defer close(done)
err := cmd.ExecuteContext(context.Background())
if err != nil {
require.ErrorIs(t, err, cliui.Canceled)
assert.ErrorIs(t, err, cliui.Canceled)
}
}()
t.Cleanup(func() {
+3 -3
View File
@@ -4,7 +4,7 @@ import (
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/assert"
"github.com/coder/coder/cli/cliui"
"github.com/coder/coder/coderd/database"
@@ -32,7 +32,7 @@ func TestWorkspaceResources(t *testing.T) {
}}, cliui.WorkspaceResourcesOptions{
WorkspaceName: "example",
})
require.NoError(t, err)
assert.NoError(t, err)
close(done)
}()
ptty.ExpectMatch("coder ssh example")
@@ -85,7 +85,7 @@ func TestWorkspaceResources(t *testing.T) {
HideAgentState: false,
HideAccess: false,
})
require.NoError(t, err)
assert.NoError(t, err)
close(done)
}()
ptty.ExpectMatch("google_compute_disk.root")
+2 -1
View File
@@ -5,6 +5,7 @@ import (
"testing"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/coder/coder/cli/cliui"
@@ -21,7 +22,7 @@ func TestSelect(t *testing.T) {
resp, err := newSelect(ptty, cliui.SelectOptions{
Options: []string{"First", "Second"},
})
require.NoError(t, err)
assert.NoError(t, err)
msgChan <- resp
}()
require.Equal(t, "First", <-msgChan)