Skip to content

fix: set a failed canceled job status correctly #3061

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

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
aafd8e5
set a failed canceled job status correctly
Kira-Pilot Jul 20, 2022
cd74afc
fix: Increase randomness for names used in tests (#3063)
mafredri Jul 20, 2022
034416f
chore: Speed up port-forward tests (#3062)
mafredri Jul 20, 2022
0c18a23
clarify start validation in schedule (#3052)
Kira-Pilot Jul 20, 2022
6199e6a
chore: bump github.com/spf13/afero from 1.9.0 to 1.9.2 (#3046)
dependabot[bot] Jul 20, 2022
4fde536
fix: Improve TestSSH reliability on macOS (#3067)
mafredri Jul 20, 2022
cf9bc71
ci: skip long jobs when only docs change (#3072)
ammario Jul 20, 2022
82f159b
chore: bump terser from 4.8.0 to 4.8.1 in /site (#3068)
dependabot[bot] Jul 20, 2022
916c388
fix: Statuses breaking line in the UI (#3071)
BrunoQuaresma Jul 20, 2022
b0c2674
ci: fix stale issue workflow (#3073)
ammario Jul 20, 2022
3e5affd
fix: Increase test timeout for TestCreate/CreateFromListWithSkip (#3077)
mafredri Jul 20, 2022
96edc8a
fix: Add `continue-on-error` to codecov action step (#3081)
mafredri Jul 20, 2022
4a7d067
fix: Increase CI timeout for postgres test (#3079)
mafredri Jul 20, 2022
62e6856
feat: add verbose error messaging (#3053)
sreya Jul 20, 2022
7768c77
added unit test for convertProvisionerJob
Kira-Pilot Jul 20, 2022
dd1327c
Update coderd/provisionerjobs_internal_test.go
Kira-Pilot Jul 21, 2022
e33a749
fix: Deadlock and race in `peer`, test improvements (#3086)
mafredri Jul 21, 2022
5b78251
refactor: Initial color palette changes (#3087)
BrunoQuaresma Jul 21, 2022
e019058
fix: avoid emitting version warning when connection error encountered…
sreya Jul 21, 2022
59b04c1
fix: coderdtest: increase ForceCancelInterval (#3085)
johnstcn Jul 21, 2022
14009c9
set a failed canceled job status correctly
Kira-Pilot Jul 20, 2022
081832f
added unit test for convertProvisionerJob
Kira-Pilot Jul 20, 2022
cc02daa
Update coderd/provisionerjobs_internal_test.go
Kira-Pilot Jul 21, 2022
3dba95c
conflicts
Kira-Pilot Jul 21, 2022
9a44002
Update coderd/templateversions_test.go
Kira-Pilot Jul 21, 2022
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
26 changes: 19 additions & 7 deletions .github/workflows/coder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ on:
- main
tags:
- "*"
paths-ignore:
- "docs/**"

pull_request:

Expand Down Expand Up @@ -217,18 +219,22 @@ jobs:
run: go run scripts/datadog-cireport/main.go gotests.xml

- uses: codecov/codecov-action@v3
# This action has a tendency to error out unexpectedly, it has
# the `fail_ci_if_error` option that defaults to `false`, but
# that is no guarantee, see:
# https://github.com/codecov/codecov-action/issues/788
continue-on-error: true
if: github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./gotests.coverage
flags: unittest-go-${{ matrix.os }}
# this flakes and sometimes fails the build
fail_ci_if_error: false

test-go-postgres:
name: "test/go/postgres"
runs-on: ubuntu-latest
timeout-minutes: 20
# This timeout must be greater than go test -timeout.
timeout-minutes: 25
steps:
- uses: actions/checkout@v3

Expand Down Expand Up @@ -279,13 +285,16 @@ jobs:
run: go run scripts/datadog-cireport/main.go gotests.xml

- uses: codecov/codecov-action@v3
# This action has a tendency to error out unexpectedly, it has
# the `fail_ci_if_error` option that defaults to `false`, but
# that is no guarantee, see:
# https://github.com/codecov/codecov-action/issues/788
continue-on-error: true
if: github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./gotests.coverage
flags: unittest-go-postgres-${{ matrix.os }}
# this flakes and sometimes fails the build
fail_ci_if_error: false

deploy:
name: "deploy"
Expand Down Expand Up @@ -429,13 +438,16 @@ jobs:
working-directory: site

- uses: codecov/codecov-action@v3
# This action has a tendency to error out unexpectedly, it has
# the `fail_ci_if_error` option that defaults to `false`, but
# that is no guarantee, see:
# https://github.com/codecov/codecov-action/issues/788
continue-on-error: true
if: github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./site/coverage/lcov.info
flags: unittest-js
# this flakes and sometimes fails the build
fail_ci_if_error: false

- name: Upload DataDog Trace
if: always() && github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/stale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ jobs:
pull-requests: write
steps:
- uses: actions/stale@v5.1.0
stale-issue-label: stale
stale-pr-label: stale
with:
stale-issue-label: stale
stale-pr-label: stale
40 changes: 40 additions & 0 deletions cli/cliflag/cliflag.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,33 @@ import (
"strings"
"time"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

// IsSetBool returns the value of the boolean flag if it is set.
// It returns false if the flag isn't set or if any error occurs attempting
// to parse the value of the flag.
func IsSetBool(cmd *cobra.Command, name string) bool {
val, ok := IsSet(cmd, name)
if !ok {
return false
}

b, err := strconv.ParseBool(val)
return err == nil && b
}

// IsSet returns the string value of the flag and whether it was set.
func IsSet(cmd *cobra.Command, name string) (string, bool) {
flag := cmd.Flag(name)
if flag == nil {
return "", false
}

return flag.Value.String(), flag.Changed
}

// String sets a string flag on the given flag set.
func String(flagset *pflag.FlagSet, name, shorthand, env, def, usage string) {
v, ok := os.LookupEnv(env)
Expand Down Expand Up @@ -67,6 +91,22 @@ func Uint8VarP(flagset *pflag.FlagSet, ptr *uint8, name string, shorthand string
flagset.Uint8VarP(ptr, name, shorthand, uint8(vi64), fmtUsage(usage, env))
}

func Bool(flagset *pflag.FlagSet, name, shorthand, env string, def bool, usage string) {
val, ok := os.LookupEnv(env)
if !ok || val == "" {
flagset.BoolP(name, shorthand, def, fmtUsage(usage, env))
return
}

valb, err := strconv.ParseBool(val)
if err != nil {
flagset.BoolP(name, shorthand, def, fmtUsage(usage, env))
return
}

flagset.BoolP(name, shorthand, valb, fmtUsage(usage, env))
}

// BoolVarP sets a bool flag on the given flag set.
func BoolVarP(flagset *pflag.FlagSet, ptr *bool, name string, shorthand string, env string, def bool, usage string) {
val, ok := os.LookupEnv(env)
Expand Down
2 changes: 1 addition & 1 deletion cli/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestCreate(t *testing.T) {

member := coderdtest.CreateAnotherUser(t, client, user.OrganizationID)
clitest.SetupConfig(t, member, root)
cmdCtx, done := context.WithTimeout(context.Background(), time.Second*3)
cmdCtx, done := context.WithTimeout(context.Background(), 10*time.Second)
go func() {
defer done()
err := cmd.ExecuteContext(cmdCtx)
Expand Down
4 changes: 3 additions & 1 deletion cli/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ func login() *cobra.Command {
// on a very old client.
err = checkVersions(cmd, client)
if err != nil {
return xerrors.Errorf("check versions: %w", err)
// Checking versions isn't a fatal error so we print a warning
// and proceed.
_, _ = fmt.Fprintln(cmd.ErrOrStderr(), cliui.Styles.Warn.Render(err.Error()))
}

hasInitialUser, err := client.HasFirstUser(cmd.Context())
Expand Down
49 changes: 27 additions & 22 deletions cli/portforward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,22 @@ func TestPortForward(t *testing.T) {
},
}

// Setup agent once to be shared between test-cases (avoid expensive
// non-parallel setup).
var (
client = coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
user = coderdtest.CreateFirstUser(t, client)
_, workspace = runAgent(t, client, user.UserID)
)

for _, c := range cases { //nolint:paralleltest // the `c := c` confuses the linter
c := c
// Avoid parallel test here because setupLocal reserves
// Delay parallel tests here because setupLocal reserves
// a free open port which is not guaranteed to be free
// after the listener closes.
//nolint:paralleltest
// between the listener closing and port-forward ready.
t.Run(c.name, func(t *testing.T) {
//nolint:paralleltest
t.Run("OnePort", func(t *testing.T) {
var (
client = coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
user = coderdtest.CreateFirstUser(t, client)
_, workspace = runAgent(t, client, user.UserID)
p1 = setupTestListener(t, c.setupRemote(t))
)
p1 := setupTestListener(t, c.setupRemote(t))

// Create a flag that forwards from local to listener 1.
localAddress, localFlag := c.setupLocal(t)
Expand All @@ -176,6 +177,8 @@ func TestPortForward(t *testing.T) {
}()
waitForPortForwardReady(t, buf)

t.Parallel() // Port is reserved, enable parallel execution.

// Open two connections simultaneously and test them out of
// sync.
d := net.Dialer{Timeout: 3 * time.Second}
Expand All @@ -196,11 +199,8 @@ func TestPortForward(t *testing.T) {
//nolint:paralleltest
t.Run("TwoPorts", func(t *testing.T) {
var (
client = coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
user = coderdtest.CreateFirstUser(t, client)
_, workspace = runAgent(t, client, user.UserID)
p1 = setupTestListener(t, c.setupRemote(t))
p2 = setupTestListener(t, c.setupRemote(t))
p1 = setupTestListener(t, c.setupRemote(t))
p2 = setupTestListener(t, c.setupRemote(t))
)

// Create a flags for listener 1 and listener 2.
Expand All @@ -223,6 +223,8 @@ func TestPortForward(t *testing.T) {
}()
waitForPortForwardReady(t, buf)

t.Parallel() // Port is reserved, enable parallel execution.

// Open a connection to both listener 1 and 2 simultaneously and
// then test them out of order.
d := net.Dialer{Timeout: 3 * time.Second}
Expand All @@ -246,10 +248,6 @@ func TestPortForward(t *testing.T) {
//nolint:paralleltest
t.Run("TCP2Unix", func(t *testing.T) {
var (
client = coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
user = coderdtest.CreateFirstUser(t, client)
_, workspace = runAgent(t, client, user.UserID)

// Find the TCP and Unix cases so we can use their setupLocal and
// setupRemote methods respectively.
tcpCase = cases[0]
Expand Down Expand Up @@ -278,6 +276,8 @@ func TestPortForward(t *testing.T) {
}()
waitForPortForwardReady(t, buf)

t.Parallel() // Port is reserved, enable parallel execution.

// Open two connections simultaneously and test them out of
// sync.
d := net.Dialer{Timeout: 3 * time.Second}
Expand All @@ -299,9 +299,6 @@ func TestPortForward(t *testing.T) {
//nolint:paralleltest
t.Run("All", func(t *testing.T) {
var (
client = coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
user = coderdtest.CreateFirstUser(t, client)
_, workspace = runAgent(t, client, user.UserID)
// These aren't fixed size because we exclude Unix on Windows.
dials = []addr{}
flags = []string{}
Expand Down Expand Up @@ -339,6 +336,8 @@ func TestPortForward(t *testing.T) {
}()
waitForPortForwardReady(t, buf)

t.Parallel() // Port is reserved, enable parallel execution.

// Open connections to all items in the "dial" array.
var (
d = net.Dialer{Timeout: 3 * time.Second}
Expand Down Expand Up @@ -425,6 +424,8 @@ func runAgent(t *testing.T, client *codersdk.Client, userID uuid.UUID) ([]coders
// setupTestListener starts accepting connections and echoing a single packet.
// Returns the listener and the listen port or Unix path.
func setupTestListener(t *testing.T, l net.Listener) string {
t.Helper()

// Wait for listener to completely exit before releasing.
done := make(chan struct{})
t.Cleanup(func() {
Expand All @@ -440,6 +441,7 @@ func setupTestListener(t *testing.T, l net.Listener) string {
for {
c, err := l.Accept()
if err != nil {
_ = l.Close()
return
}

Expand Down Expand Up @@ -479,6 +481,7 @@ func testAccept(t *testing.T, c net.Conn) {
}

func assertReadPayload(t *testing.T, r io.Reader, payload []byte) {
t.Helper()
b := make([]byte, len(payload)+16)
n, err := r.Read(b)
assert.NoError(t, err, "read payload")
Expand All @@ -487,12 +490,14 @@ func assertReadPayload(t *testing.T, r io.Reader, payload []byte) {
}

func assertWritePayload(t *testing.T, w io.Writer, payload []byte) {
t.Helper()
n, err := w.Write(payload)
assert.NoError(t, err, "write payload")
assert.Equal(t, len(payload), n, "payload length does not match")
}

func waitForPortForwardReady(t *testing.T, output *threadSafeBuffer) {
t.Helper()
for i := 0; i < 100; i++ {
time.Sleep(250 * time.Millisecond)

Expand Down
Loading