MCPcopy
hub / github.com/cornelk/hashmap / TestConcurrentInsertDelete

Function TestConcurrentInsertDelete

hashmap_test.go:405–454  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

403}
404
405func TestConcurrentInsertDelete(t *testing.T) {
406 t.Parallel()
407
408 for i := 0; i < 200; i++ {
409 el1 := &ListElement[int, int]{
410 key: 111,
411 keyHash: 111,
412 }
413 el2 := &ListElement[int, int]{
414 key: 222,
415 keyHash: 222,
416 }
417 el3 := &ListElement[int, int]{
418 key: 333,
419 keyHash: 333,
420 }
421 newIl := &ListElement[int, int]{
422 key: 223,
423 keyHash: 223,
424 }
425 l := NewList[int, int]()
426 l.Add(nil, el1.keyHash, el1.key, 111)
427 l.Add(nil, el2.keyHash, el2.key, 222)
428 l.Add(nil, el3.keyHash, el3.key, 333)
429 wg := sync.WaitGroup{}
430 wg.Add(2)
431
432 go func() {
433 rand.Seed(int64(time.Now().Nanosecond()))
434 time.Sleep(time.Duration(rand.Intn(10)))
435 l.Delete(el2)
436 wg.Done()
437 }()
438 go func() {
439 defer wg.Done()
440 rand.Seed(int64(time.Now().Nanosecond()))
441 time.Sleep(time.Duration(rand.Intn(10)))
442 for {
443 if _, _, inserted := l.Add(nil, newIl.keyHash, newIl.key, 223); inserted {
444 return
445 }
446 }
447 }()
448 wg.Wait()
449
450 assert.Equal(t, 3, l.Len())
451 _, found, _ := l.search(nil, newIl.keyHash, newIl.key)
452 assert.True(t, found != nil)
453 }
454}

Callers

nothing calls this directly

Calls 7

EqualFunction · 0.92
TrueFunction · 0.92
NewListFunction · 0.85
AddMethod · 0.80
DeleteMethod · 0.80
searchMethod · 0.80
LenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…