MCPcopy Index your code
hub / github.com/coder/coder / TestReplicas

Function TestReplicas

enterprise/coderd/replicas_test.go:21–189  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19)
20
21func TestReplicas(t *testing.T) {
22 t.Parallel()
23
24 t.Run("ErrorWithoutLicense", func(t *testing.T) {
25 t.Parallel()
26 ctx := testutil.Context(t, testutil.WaitLong)
27 // This will error because replicas are expected to instantly report
28 // errors when the license is not present.
29 db, pubsub := dbtestutil.NewDB(t)
30 firstClient, _ := coderdenttest.New(t, &coderdenttest.Options{
31 Options: &coderdtest.Options{
32 IncludeProvisionerDaemon: true,
33 Database: db,
34 Pubsub: pubsub,
35 },
36 DontAddLicense: true,
37 ReplicaErrorGracePeriod: time.Nanosecond,
38 })
39 secondClient, _, secondAPI, _ := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
40 Options: &coderdtest.Options{
41 Database: db,
42 Pubsub: pubsub,
43 },
44 DontAddFirstUser: true,
45 DontAddLicense: true,
46 ReplicaErrorGracePeriod: time.Nanosecond,
47 })
48 secondClient.SetSessionToken(firstClient.SessionToken())
49
50 testutil.Eventually(ctx, t, func(ctx context.Context) (done bool) {
51 ents, err := secondClient.Entitlements(ctx)
52 return assert.NoError(t, err, "unexpected error from secondClient.Entitlements") &&
53 len(ents.Errors) == 1
54 }, testutil.IntervalFast)
55 _ = secondAPI.Close()
56
57 testutil.Eventually(ctx, t, func(ctx context.Context) (done bool) {
58 ents, err := firstClient.Entitlements(ctx)
59 return assert.NoError(t, err, "unexpected error from firstClient.Entitlements") &&
60 len(ents.Warnings) == 0
61 }, testutil.IntervalFast)
62 })
63 t.Run("DoesNotErrorBeforeGrace", func(t *testing.T) {
64 t.Parallel()
65 db, pubsub := dbtestutil.NewDB(t)
66 firstClient, _ := coderdenttest.New(t, &coderdenttest.Options{
67 Options: &coderdtest.Options{
68 IncludeProvisionerDaemon: true,
69 Database: db,
70 Pubsub: pubsub,
71 },
72 DontAddLicense: true,
73 })
74 secondClient, _, secondAPI, _ := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
75 Options: &coderdtest.Options{
76 Database: db,
77 Pubsub: pubsub,
78 },

Callers

nothing calls this directly

Calls 15

ContextFunction · 0.92
NewDBFunction · 0.92
NewFunction · 0.92
NewWithAPIFunction · 0.92
EventuallyFunction · 0.92
NewFunction · 0.92
LoggerFunction · 0.92
GenerateTLSCertificateFunction · 0.92
setupWorkspaceAgentFunction · 0.85
SetSessionTokenMethod · 0.80
EntitlementsMethod · 0.80
ReplicasMethod · 0.80

Tested by

no test coverage detected