Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit90ed0f2

Browse files
test: improve tests
1 parent78e0f42 commit90ed0f2

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

‎enterprise/coderd/prebuilds/reconcile_test.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package prebuilds_test
33
import (
44
"context"
55
"database/sql"
6-
"encoding/json"
76
"fmt"
87
"sync"
98
"testing"
@@ -653,6 +652,7 @@ func TestSkippingHardLimitedPresets(t *testing.T) {
653652
t.Skip("This test requires postgres")
654653
}
655654

655+
// Test cases verify the behavior of prebuild creation depending on configured failure limits
656656
testCases:= []struct {
657657
namestring
658658
hardLimitint64
@@ -687,13 +687,16 @@ func TestSkippingHardLimitedPresets(t *testing.T) {
687687
db,pubSub:=dbtestutil.NewDB(t)
688688
controller:=prebuilds.NewStoreReconciler(db,pubSub,cfg,logger,clock,prometheus.NewRegistry())
689689

690+
// Set up test environment with a template, version, and preset
690691
ownerID:=uuid.New()
691692
dbgen.User(t,db, database.User{
692693
ID:ownerID,
693694
})
694695
org,template:=setupTestDBTemplate(t,db,ownerID,templateDeleted)
695696
templateVersionID:=setupTestDBTemplateVersion(ctx,t,clock,db,pubSub,org.ID,ownerID,template.ID)
696697
preset:=setupTestDBPreset(t,db,templateVersionID,1,uuid.New().String())
698+
699+
// Create a failed prebuild workspace that counts toward the hard failure limit.
697700
prebuiltWorkspace:=setupTestDBPrebuild(
698701
t,
699702
clock,
@@ -708,36 +711,32 @@ func TestSkippingHardLimitedPresets(t *testing.T) {
708711
)
709712
_=prebuiltWorkspace
710713

711-
//Make sure we have onlyoneworkspace. Corresponding job hasfailedstatus.
714+
//Verify initial state:one failedworkspace exists
712715
workspaces,err:=db.GetWorkspacesByTemplateID(ctx,template.ID)
713716
require.NoError(t,err)
714717
workspaceCount:=len(workspaces)
715718
require.Equal(t,1,workspaceCount)
716719

717-
// Advance clock toavoid backoff.
720+
// Advance clock tobypass backoff mechanisms
718721
clock.Advance(time.Second).MustWait(ctx)
719722

720-
// ReconcileAll won't have any effect because we hit hard limit.
721-
722-
// ReconcileAll tries to create 1 desired instance, because previous build is failed.
723-
// But it maybe hard-limited depending on test configuration.
723+
// Trigger reconciliation to attempt creating a new prebuild
724+
// The outcome depends on whether the hard limit has been reached
724725
require.NoError(t,controller.ReconcileAll(ctx))
725726

727+
// Verify the final state after reconciliation
726728
workspaces,err=db.GetWorkspacesByTemplateID(ctx,template.ID)
727729
require.NoError(t,err)
728730

729731
iftc.isHardLimitHit {
730-
//We didn't try to create 2nd workspace, because we hit hard limit before.
732+
//When hard limit is reached, no new workspace should be created
731733
workspaceCount=len(workspaces)
732734
require.Equal(t,1,workspaceCount)
733735
}else {
734-
//We created 2nd workspace, hard limit wasn't hit.
736+
//When hard limit is not reached, a new workspace should be created
735737
workspaceCount=len(workspaces)
736738
require.Equal(t,2,workspaceCount)
737739
}
738-
739-
workspacesInJSON,err:=json.Marshal(workspaces)
740-
fmt.Printf("workspacesInJSON: %s\n",workspacesInJSON)
741740
})
742741
}
743742
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp