Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
6 changes: 5 additions & 1 deletion coderd/provisionerjobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,11 @@ func convertProvisionerJob(provisionerJob database.ProvisionerJob) codersdk.Prov
switch {
case provisionerJob.CanceledAt.Valid:
if provisionerJob.CompletedAt.Valid {
job.Status = codersdk.ProvisionerJobCanceled
if job.Error == "" {
job.Status = codersdk.ProvisionerJobCanceled
} else {
job.Status = codersdk.ProvisionerJobFailed
}
} else {
job.Status = codersdk.ProvisionerJobCanceling
}
Expand Down
104 changes: 104 additions & 0 deletions coderd/provisionerjobs_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package coderd
import (
"context"
"crypto/sha256"
"database/sql"
"encoding/json"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -146,6 +147,109 @@ func TestProvisionerJobLogs_Unit(t *testing.T) {
})
}

func TestConvertProvisionerJob_Unit(t *testing.T) {
t.Parallel()
validNullTimeMock := sql.NullTime{
Time: database.Now(),
Valid: true,
}
invalidNullTimeMock := sql.NullTime{}
errorMock := sql.NullString{
String: "error",
Valid: true,
}
testCases := []struct {
name string
input database.ProvisionerJob
expected codersdk.ProvisionerJob
}{
{
name: "empty",
input: database.ProvisionerJob{},
expected: codersdk.ProvisionerJob{
Status: codersdk.ProvisionerJobPending,
},
},
{
name: "cancellation pending",
input: database.ProvisionerJob{
CanceledAt: validNullTimeMock,
CompletedAt: invalidNullTimeMock,
},
expected: codersdk.ProvisionerJob{
Status: codersdk.ProvisionerJobCanceling,
},
},
{
name: "cancellation failed",
input: database.ProvisionerJob{
CanceledAt: validNullTimeMock,
CompletedAt: validNullTimeMock,
Error: errorMock,
},
expected: codersdk.ProvisionerJob{
CompletedAt: &validNullTimeMock.Time,
Status: codersdk.ProvisionerJobFailed,
Error: errorMock.String,
},
},
{
name: "cancellation succeeded",
input: database.ProvisionerJob{
CanceledAt: validNullTimeMock,
CompletedAt: validNullTimeMock,
},
expected: codersdk.ProvisionerJob{
CompletedAt: &validNullTimeMock.Time,
Status: codersdk.ProvisionerJobCanceled,
},
},
{
name: "job pending",
input: database.ProvisionerJob{
StartedAt: invalidNullTimeMock,
},
expected: codersdk.ProvisionerJob{
Status: codersdk.ProvisionerJobPending,
},
},
{
name: "job failed",
input: database.ProvisionerJob{
CompletedAt: validNullTimeMock,
StartedAt: validNullTimeMock,
Error: errorMock,
},
expected: codersdk.ProvisionerJob{
CompletedAt: &validNullTimeMock.Time,
StartedAt: &validNullTimeMock.Time,
Error: errorMock.String,
Status: codersdk.ProvisionerJobFailed,
},
},
{
name: "job succeeded",
input: database.ProvisionerJob{
CompletedAt: validNullTimeMock,
StartedAt: validNullTimeMock,
},
expected: codersdk.ProvisionerJob{
CompletedAt: &validNullTimeMock.Time,
StartedAt: &validNullTimeMock.Time,
Status: codersdk.ProvisionerJobSucceeded,
},
},
}
for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()
actual := convertProvisionerJob(testCase.input)
assert.Equal(t, testCase.expected, actual)
})
}
}

type fakePubSub struct {
t *testing.T
cond *sync.Cond
Expand Down
8 changes: 7 additions & 1 deletion coderd/templateversions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ func TestPatchCancelTemplateVersion(t *testing.T) {
var apiErr *codersdk.Error
require.ErrorAs(t, err, &apiErr)
require.Equal(t, http.StatusPreconditionFailed, apiErr.StatusCode())
require.Eventually(t, func() bool {
var err error
version, err = client.TemplateVersion(context.Background(), version.ID)
require.NoError(t, err)
return version.Job.Status == codersdk.ProvisionerJobFailed
}, 5*time.Second, 25*time.Millisecond)
})
t.Run("Success", func(t *testing.T) {
t.Parallel()
Expand All @@ -151,7 +157,7 @@ func TestPatchCancelTemplateVersion(t *testing.T) {
var err error
version, err = client.TemplateVersion(context.Background(), version.ID)
require.NoError(t, err)
return version.Job.Status == codersdk.ProvisionerJobCanceled
return version.Job.Status == codersdk.ProvisionerJobFailed // cancel times out
}, 5*time.Second, 25*time.Millisecond)
})
}
Expand Down
2 changes: 1 addition & 1 deletion coderd/workspacebuilds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func TestPatchCancelWorkspaceBuild(t *testing.T) {
var err error
build, err = client.WorkspaceBuild(context.Background(), build.ID)
require.NoError(t, err)
return build.Job.Status == codersdk.ProvisionerJobCanceled
return build.Job.Status == codersdk.ProvisionerJobFailed // this is timing out
}, 5*time.Second, 25*time.Millisecond)
}

Expand Down