MCPcopy Create free account
hub / github.com/ContentSquare/chproxy / testConcurrentQuery

Function testConcurrentQuery

scope_test.go:428–459  ·  view source on GitHub ↗
(c *cluster, u *user, cu *clusterUser, concurrency int, expectedSessionHostMap map[string]string)

Source from the content-addressed store, hash-verified

426}
427
428func testConcurrentQuery(c *cluster, u *user, cu *clusterUser, concurrency int, expectedSessionHostMap map[string]string) error {
429 ch := make(chan map[string]string, 10000)
430
431 f := func(sessionId string) map[string]string {
432 s := testGetScope(c, u, cu, sessionId)
433 // user set sessionId
434 s.sessionId = sessionId
435 // concurrent task wait
436 s.incQueued()
437 time.Sleep(50 * time.Millisecond)
438 s.dec()
439 // return wake task's new host
440 // same sessionId should get same host addr
441 return map[string]string{sessionId: s.host.Host()}
442 }
443
444 for i := 0; i < concurrency; i++ {
445 sessionId := strconv.Itoa(i % 4)
446 go func() {
447 ch <- f(sessionId)
448 }()
449 }
450 for i := 0; i < concurrency; i++ {
451 sessionHost := <-ch
452 for sessionId, host := range sessionHost {
453 if expectedSessionHostMap[sessionId] != host {
454 return fmt.Errorf("incQueue waked task sessionId: %s,expected host: %v, get: %v", sessionId, expectedSessionHostMap[sessionId], host)
455 }
456 }
457 }
458 return nil
459}
460
461func testGetCluster() *cluster {
462 c := &cluster{

Callers 1

TestIncQueuedFunction · 0.85

Calls 4

testGetScopeFunction · 0.85
incQueuedMethod · 0.80
HostMethod · 0.80
decMethod · 0.45

Tested by

no test coverage detected