(b *testing.B, count int, as *ActiveUsers)
| 130 | } |
| 131 | |
| 132 | func startGoroutinesDoingUpdates(b *testing.B, count int, as *ActiveUsers) { |
| 133 | done := sync.WaitGroup{} |
| 134 | stop := atomic.NewBool(false) |
| 135 | |
| 136 | started := sync.WaitGroup{} |
| 137 | for j := range count { |
| 138 | done.Add(1) |
| 139 | started.Add(1) |
| 140 | userID := fmt.Sprintf("user-%d", j) |
| 141 | go func() { |
| 142 | defer done.Done() |
| 143 | started.Done() |
| 144 | |
| 145 | ts := int64(0) |
| 146 | for !stop.Load() { |
| 147 | ts++ |
| 148 | as.UpdateUserTimestamp(userID, ts) |
| 149 | |
| 150 | // Give other goroutines a chance too. |
| 151 | if ts%1000 == 0 { |
| 152 | runtime.Gosched() |
| 153 | } |
| 154 | } |
| 155 | }() |
| 156 | } |
| 157 | started.Wait() |
| 158 | |
| 159 | b.Cleanup(func() { |
| 160 | // Ask goroutines to stop, and then wait until they do. |
| 161 | stop.Store(true) |
| 162 | done.Wait() |
| 163 | }) |
| 164 | } |
no test coverage detected