Skip to content

chore: avoid concurrent usage of t.FailNow #1683

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

Merged
merged 3 commits into from
May 24, 2022
Merged
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
2 changes: 2 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ run:
concurrency: 4
skip-dirs:
- node_modules
skip-files:
- scripts/rules.go
timeout: 5m

# Over time, add more and more linters from
Expand Down
17 changes: 9 additions & 8 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/pion/udp"
"github.com/pion/webrtc/v3"
"github.com/pkg/sftp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
"golang.org/x/crypto/ssh"
Expand Down Expand Up @@ -119,7 +120,7 @@ func TestAgent(t *testing.T) {
done := make(chan struct{})
go func() {
conn, err := local.Accept()
require.NoError(t, err)
assert.NoError(t, err)
_ = conn.Close()
close(done)
}()
Expand Down Expand Up @@ -367,7 +368,7 @@ func setupSSHCommand(t *testing.T, beforeArgs []string, afterArgs []string) *exe
return
}
ssh, err := agentConn.SSH()
require.NoError(t, err)
assert.NoError(t, err)
go io.Copy(conn, ssh)
go io.Copy(ssh, conn)
}
Expand Down Expand Up @@ -409,7 +410,7 @@ func setupAgent(t *testing.T, metadata agent.Metadata, ptyTimeout time.Duration)
})
api := proto.NewDRPCPeerBrokerClient(provisionersdk.Conn(client))
stream, err := api.NegotiateConnection(context.Background())
require.NoError(t, err)
assert.NoError(t, err)
conn, err := peerbroker.Dial(stream, []webrtc.ICEServer{}, &peer.ConnOptions{
Logger: slogtest.Make(t, nil),
})
Expand Down Expand Up @@ -444,13 +445,13 @@ func testAccept(t *testing.T, c net.Conn) {
func assertReadPayload(t *testing.T, r io.Reader, payload []byte) {
b := make([]byte, len(payload)+16)
n, err := r.Read(b)
require.NoError(t, err, "read payload")
require.Equal(t, len(payload), n, "read payload length does not match")
require.Equal(t, payload, b[:n])
assert.NoError(t, err, "read payload")
assert.Equal(t, len(payload), n, "read payload length does not match")
assert.Equal(t, payload, b[:n])
}

func assertWritePayload(t *testing.T, w io.Writer, payload []byte) {
n, err := w.Write(payload)
require.NoError(t, err, "write payload")
require.Equal(t, len(payload), n, "payload length does not match")
assert.NoError(t, err, "write payload")
assert.Equal(t, len(payload), n, "payload length does not match")
}
4 changes: 2 additions & 2 deletions cli/cliui/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions cli/cliui/prompt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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
}()

Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions cli/cliui/provisionerjob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions cli/cliui/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion cli/cliui/select_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions cli/configssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"testing"

"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"cdr.dev/slog/sloggers/slogtest"
Expand Down Expand Up @@ -96,7 +97,7 @@ func TestConfigSSH(t *testing.T) {
return
}
ssh, err := agentConn.SSH()
require.NoError(t, err)
assert.NoError(t, err)
go io.Copy(conn, ssh)
go io.Copy(ssh, conn)
}
Expand All @@ -120,7 +121,7 @@ func TestConfigSSH(t *testing.T) {
go func() {
defer close(doneChan)
err := cmd.Execute()
require.NoError(t, err)
assert.NoError(t, err)
}()
<-doneChan

Expand Down
13 changes: 7 additions & 6 deletions cli/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/coder/coder/cli/clitest"
Expand Down Expand Up @@ -34,7 +35,7 @@ func TestCreate(t *testing.T) {
go func() {
defer close(doneChan)
err := cmd.Execute()
require.NoError(t, err)
assert.NoError(t, err)
}()
matches := []string{
"Confirm create", "yes",
Expand All @@ -61,7 +62,7 @@ func TestCreate(t *testing.T) {
go func() {
defer done()
err := cmd.ExecuteContext(cmdCtx)
require.NoError(t, err)
assert.NoError(t, err)
}()
// No pty interaction needed since we use the -y skip prompt flag
<-cmdCtx.Done()
Expand All @@ -84,7 +85,7 @@ func TestCreate(t *testing.T) {
go func() {
defer close(doneChan)
err := cmd.Execute()
require.NoError(t, err)
assert.NoError(t, err)
}()
matches := []string{
"Specify a name", "my-workspace",
Expand Down Expand Up @@ -122,7 +123,7 @@ func TestCreate(t *testing.T) {
go func() {
defer close(doneChan)
err := cmd.Execute()
require.NoError(t, err)
assert.NoError(t, err)
}()

matches := []string{
Expand Down Expand Up @@ -166,7 +167,7 @@ func TestCreate(t *testing.T) {
go func() {
defer close(doneChan)
err := cmd.Execute()
require.NoError(t, err)
assert.NoError(t, err)
}()

matches := []string{
Expand Down Expand Up @@ -207,7 +208,7 @@ func TestCreate(t *testing.T) {
go func() {
defer close(doneChan)
err := cmd.Execute()
require.EqualError(t, err, "Parameter value absent in parameter file for \"region\"!")
assert.EqualError(t, err, "Parameter value absent in parameter file for \"region\"!")
}()
<-doneChan
removeTmpDirUntilSuccess(t, tempDir)
Expand Down
8 changes: 6 additions & 2 deletions cli/delete_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package cli_test

import (
"io"
"testing"

"github.com/stretchr/testify/require"
"github.com/stretchr/testify/assert"

"github.com/coder/coder/cli/clitest"
"github.com/coder/coder/coderd/coderdtest"
Expand All @@ -29,7 +30,10 @@ func TestDelete(t *testing.T) {
go func() {
defer close(doneChan)
err := cmd.Execute()
require.NoError(t, err)
// When running with the race detector on, we sometimes get an EOF.
if err != nil {
assert.ErrorIs(t, err, io.EOF)
}
}()
pty.ExpectMatch("Cleaning Up")
<-doneChan
Expand Down
9 changes: 5 additions & 4 deletions cli/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/coder/coder/cli/clitest"
Expand Down Expand Up @@ -35,7 +36,7 @@ func TestLogin(t *testing.T) {
go func() {
defer close(doneChan)
err := root.Execute()
require.NoError(t, err)
assert.NoError(t, err)
}()

matches := []string{
Expand Down Expand Up @@ -71,7 +72,7 @@ func TestLogin(t *testing.T) {
go func() {
defer close(doneChan)
err := root.ExecuteContext(ctx)
require.ErrorIs(t, err, context.Canceled)
assert.ErrorIs(t, err, context.Canceled)
}()

matches := []string{
Expand Down Expand Up @@ -106,7 +107,7 @@ func TestLogin(t *testing.T) {
go func() {
defer close(doneChan)
err := root.Execute()
require.NoError(t, err)
assert.NoError(t, err)
}()

pty.ExpectMatch("Paste your token here:")
Expand All @@ -131,7 +132,7 @@ func TestLogin(t *testing.T) {
defer close(doneChan)
err := root.ExecuteContext(ctx)
// An error is expected in this case, since the login wasn't successful:
require.Error(t, err)
assert.Error(t, err)
}()

pty.ExpectMatch("Paste your token here:")
Expand Down
3 changes: 2 additions & 1 deletion cli/logout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli_test
import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/coder/coder/cli/clitest"
Expand All @@ -25,7 +26,7 @@ func TestLogout(t *testing.T) {
go func() {
defer close(doneChan)
err := root.Execute()
require.NoError(t, err)
assert.NoError(t, err)
}()

pty.ExpectMatch("Paste your token here:")
Expand Down
Loading