Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore: fix flake in create-admin-user test #6103

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 4 commits into from
Feb 8, 2023
Merged
Changes from 2 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
55 changes: 37 additions & 18 deletions cli/server_createadminuser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"runtime"
"testing"
"time"

"github.com/google/uuid"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -135,14 +136,20 @@ func TestServerCreateAdminUser(t *testing.T) {
errC <- err
}()

pty.ExpectMatch("Creating user...")
pty.ExpectMatch("Generating user SSH key...")
pty.ExpectMatch(fmt.Sprintf("Adding user to organization %q (%s) as admin...", org1Name, org1ID.String()))
pty.ExpectMatch(fmt.Sprintf("Adding user to organization %q (%s) as admin...", org2Name, org2ID.String()))
pty.ExpectMatch("User created successfully.")
pty.ExpectMatch(username)
pty.ExpectMatch(email)
pty.ExpectMatch("****")
// Sometimes generating SSH keys takes a really long time if there isn't
// enough entropy. We don't want the tests to fail in these cases.
//nolint:gocritic
ctx, cancel := context.WithTimeout(ctx, 1*time.Minute)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ctx, cancel := context.WithTimeout(ctx, 1*time.Minute)
ctx, cancel := context.WithTimeout(ctx, testutil.WaitSuperLong)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait we have that? awesome

defer cancel()

pty.ExpectMatchContext(ctx, "Creating user...")
pty.ExpectMatchContext(ctx, "Generating user SSH key...")
pty.ExpectMatchContext(ctx, fmt.Sprintf("Adding user to organization %q (%s) as admin...", org1Name, org1ID.String()))
pty.ExpectMatchContext(ctx, fmt.Sprintf("Adding user to organization %q (%s) as admin...", org2Name, org2ID.String()))
pty.ExpectMatchContext(ctx, "User created successfully.")
pty.ExpectMatchContext(ctx, username)
pty.ExpectMatchContext(ctx, email)
pty.ExpectMatchContext(ctx, "****")

require.NoError(t, <-errC)

Expand All @@ -162,7 +169,7 @@ func TestServerCreateAdminUser(t *testing.T) {
defer cancelFunc()

t.Setenv("CODER_POSTGRES_URL", connectionURL)
t.Setenv("CODER_SSH_KEYGEN_ALGORITHM", "ecdsa")
t.Setenv("CODER_SSH_KEYGEN_ALGORITHM", "ed25519")
t.Setenv("CODER_USERNAME", username)
t.Setenv("CODER_EMAIL", email)
t.Setenv("CODER_PASSWORD", password)
Expand All @@ -178,10 +185,16 @@ func TestServerCreateAdminUser(t *testing.T) {
errC <- err
}()

pty.ExpectMatch("User created successfully.")
pty.ExpectMatch(username)
pty.ExpectMatch(email)
pty.ExpectMatch("****")
// Sometimes generating SSH keys takes a really long time if there isn't
// enough entropy. We don't want the tests to fail in these cases.
//nolint:gocritic
ctx, cancel := context.WithTimeout(ctx, 1*time.Minute)
defer cancel()

pty.ExpectMatchContext(ctx, "User created successfully.")
pty.ExpectMatchContext(ctx, username)
pty.ExpectMatchContext(ctx, email)
pty.ExpectMatchContext(ctx, "****")

require.NoError(t, <-errC)

Expand All @@ -204,7 +217,7 @@ func TestServerCreateAdminUser(t *testing.T) {
root, _ := clitest.New(t,
"server", "create-admin-user",
"--postgres-url", connectionURL,
"--ssh-keygen-algorithm", "rsa4096",
"--ssh-keygen-algorithm", "ed25519",
)
pty := ptytest.New(t)
root.SetIn(pty.Input())
Expand All @@ -226,10 +239,16 @@ func TestServerCreateAdminUser(t *testing.T) {
pty.ExpectMatch("> Confirm password")
pty.WriteLine(password)

pty.ExpectMatch("User created successfully.")
pty.ExpectMatch(username)
pty.ExpectMatch(email)
pty.ExpectMatch("****")
// Sometimes generating SSH keys takes a really long time if there isn't
// enough entropy. We don't want the tests to fail in these cases.
//nolint:gocritic
ctx, cancel := context.WithTimeout(ctx, 1*time.Minute)
defer cancel()

pty.ExpectMatchContext(ctx, "User created successfully.")
pty.ExpectMatchContext(ctx, username)
pty.ExpectMatchContext(ctx, email)
pty.ExpectMatchContext(ctx, "****")

require.NoError(t, <-errC)

Expand Down