mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-05-18 04:54:30 +02:00
WIP: Batch message INSERTs
This commit is contained in:
parent
499ac76c43
commit
b4933a5645
4 changed files with 107 additions and 8 deletions
25
util/batching_queue_test.go
Normal file
25
util/batching_queue_test.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
package util_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"heckel.io/ntfy/util"
|
||||
"math/rand"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestConcurrentQueue_Next(t *testing.T) {
|
||||
q := util.NewBatchingQueue[int](25, 200*time.Millisecond)
|
||||
go func() {
|
||||
for batch := range q.Pop() {
|
||||
fmt.Printf("Batch of %d items\n", len(batch))
|
||||
}
|
||||
}()
|
||||
for i := 0; i < 1000; i++ {
|
||||
go func(i int) {
|
||||
time.Sleep(time.Duration(rand.Intn(1000)) * time.Millisecond)
|
||||
q.Push(i)
|
||||
}(i)
|
||||
}
|
||||
time.Sleep(2 * time.Second)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue