1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2025-11-29 19:59:59 +01:00
This commit is contained in:
binwiederhier 2025-08-08 16:10:49 -04:00
parent 97410db301
commit fe5c844a21
2 changed files with 24 additions and 2 deletions

View file

@ -8,8 +8,8 @@ import (
"net/netip"
"path/filepath"
"strings"
"time"
"sync"
"time"
_ "github.com/mattn/go-sqlite3" // SQLite driver
"heckel.io/ntfy/v2/log"
@ -283,8 +283,8 @@ var (
type messageCache struct {
db *sql.DB
queue *util.BatchingQueue[*message]
mu sync.Mutex
nop bool
mu sync.Mutex
}
// newSqliteCache creates a SQLite file-backed cache

View file

@ -3,8 +3,10 @@ package server
import (
"database/sql"
"fmt"
"github.com/stretchr/testify/assert"
"net/netip"
"path/filepath"
"sync"
"testing"
"time"
@ -90,6 +92,26 @@ func testCacheMessages(t *testing.T, c *messageCache) {
require.Empty(t, messages)
}
func TestSqliteCache_MessagesLock(t *testing.T) {
testCacheMessagesLock(t, newSqliteTestCache(t))
}
func TestMemCache_MessagesLock(t *testing.T) {
testCacheMessagesLock(t, newMemTestCache(t))
}
func testCacheMessagesLock(t *testing.T, c *messageCache) {
var wg sync.WaitGroup
for i := 0; i < 5000; i++ {
wg.Add(1)
go func() {
assert.Nil(t, c.AddMessage(newDefaultMessage("mytopic", "test message")))
wg.Done()
}()
}
wg.Wait()
}
func TestSqliteCache_MessagesScheduled(t *testing.T) {
testCacheMessagesScheduled(t, newSqliteTestCache(t))
}