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

Function TestUserSkillLimitConcurrentCreates

coderd/userskills_test.go:236–282  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

234}
235
236func TestUserSkillLimitConcurrentCreates(t *testing.T) {
237 t.Parallel()
238
239 adminClient := coderdtest.New(t, nil)
240 firstUser := coderdtest.CreateFirstUser(t, adminClient)
241 ownerClient, _ := coderdtest.CreateAnotherUser(t, adminClient, firstUser.OrganizationID)
242 owner := codersdk.NewExperimentalClient(ownerClient)
243 ctx := testutil.Context(t, testutil.WaitLong)
244
245 for i := range skills.MaxPersonalSkillsPerUser - 1 {
246 name := fmt.Sprintf("concurrent-limit-skill-%03d", i)
247 _, err := owner.CreateUserSkill(ctx, codersdk.Me, codersdk.CreateUserSkillRequest{
248 Content: userSkillMarkdown(name, "Limit", "Body."),
249 })
250 require.NoError(t, err)
251 }
252
253 const attempts = 8
254 start := make(chan struct{})
255 results := make(chan error, attempts)
256 for i := range attempts {
257 go func() {
258 <-start
259 name := fmt.Sprintf("concurrent-limit-overflow-%03d", i)
260 _, err := owner.CreateUserSkill(ctx, codersdk.Me, codersdk.CreateUserSkillRequest{
261 Content: userSkillMarkdown(name, "Limit", "Body."),
262 })
263 results <- err
264 }()
265 }
266 close(start)
267
268 successes := 0
269 for range attempts {
270 err := <-results
271 if err == nil {
272 successes++
273 continue
274 }
275 requireSDKErrorStatus(t, err, http.StatusConflict)
276 }
277 assert.Equal(t, 1, successes)
278
279 list, err := owner.UserSkills(ctx, codersdk.Me)
280 require.NoError(t, err)
281 assert.Len(t, list, skills.MaxPersonalSkillsPerUser)
282}
283
284func TestUserSkillRequestAllowsEscapedMaxSizeContent(t *testing.T) {
285 t.Parallel()

Callers

nothing calls this directly

Calls 11

CreateUserSkillMethod · 0.95
UserSkillsMethod · 0.95
NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
NewExperimentalClientFunction · 0.92
ContextFunction · 0.92
requireSDKErrorStatusFunction · 0.85
userSkillMarkdownFunction · 0.70
EqualMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected