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

Function TestMarkTemporary

aibridge/keypool/keypool_test.go:138–217  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

136}
137
138func TestMarkTemporary(t *testing.T) {
139 t.Parallel()
140
141 tests := []struct {
142 name string
143 cooldown time.Duration
144 setup func(t *testing.T, pool *keypool.Pool, clk *quartz.Mock) *keypool.Key
145 expectedState keypool.KeyState
146 expectedTransition bool
147 }{
148 {
149 // valid -> temporary: key becomes unavailable.
150 name: "valid_to_temporary",
151 cooldown: 60 * time.Second,
152 setup: func(t *testing.T, pool *keypool.Pool, _ *quartz.Mock) *keypool.Key {
153 key, keyPoolErr := pool.Walker().Next()
154 require.Nil(t, keyPoolErr)
155 return key
156 },
157 expectedState: keypool.KeyStateTemporary,
158 expectedTransition: true,
159 },
160 {
161 // temporary -> temporary: new cooldown is longer,
162 // so the deadline is extended.
163 name: "temporary_to_temporary_extends_cooldown",
164 cooldown: 60 * time.Second,
165 setup: func(t *testing.T, pool *keypool.Pool, _ *quartz.Mock) *keypool.Key {
166 key, keyPoolErr := pool.Walker().Next()
167 require.Nil(t, keyPoolErr)
168 key.MarkTemporary(10 * time.Second)
169 return key
170 },
171 expectedState: keypool.KeyStateTemporary,
172 expectedTransition: false,
173 },
174 {
175 // temporary -> temporary: new cooldown is shorter,
176 // so the existing longer deadline is preserved.
177 name: "temporary_to_temporary_keeps_longer_cooldown",
178 cooldown: 10 * time.Second,
179 setup: func(t *testing.T, pool *keypool.Pool, _ *quartz.Mock) *keypool.Key {
180 key, keyPoolErr := pool.Walker().Next()
181 require.Nil(t, keyPoolErr)
182 key.MarkTemporary(60 * time.Second)
183 return key
184 },
185 expectedState: keypool.KeyStateTemporary,
186 expectedTransition: false,
187 },
188 {
189 // permanent -> permanent: no-op, permanent is irreversible.
190 name: "permanent_to_temporary_is_no_op",
191 cooldown: 60 * time.Second,
192 setup: func(t *testing.T, pool *keypool.Pool, _ *quartz.Mock) *keypool.Key {
193 key, keyPoolErr := pool.Walker().Next()
194 require.Nil(t, keyPoolErr)
195 key.MarkPermanent()

Callers

nothing calls this directly

Calls 8

NewFunction · 0.92
WalkerMethod · 0.80
MarkTemporaryMethod · 0.80
MarkPermanentMethod · 0.80
NextMethod · 0.65
RunMethod · 0.65
EqualMethod · 0.45
StateMethod · 0.45

Tested by

no test coverage detected