package mdb /*Copyright (c) 2022, John David Lee All rights reserved. This source code is licensed under the BSD-style license found in the LICENSE file in the root directory of this source tree. */ import ( "sync" "testing" "time" ) func TestDatabase(t *testing.T) { testWithDB(t, "multiple writers", func(t *testing.T, db *DB) { wg := sync.WaitGroup{} N := 64 wg.Add(64) for i := 0; i < N; i++ { go func() { defer wg.Done() for j := 0; j < 1024; j++ { db.RandAction() } }() } wg.Wait() }) testWithDB(t, "clean before", func(t *testing.T, db *DB) { db.RandAction() db.RandAction() db.RandAction() time.Sleep(2 * time.Second) db.CleanBefore(0) if db.MaxSeqNum() == 0 { t.Fatal(db.MaxSeqNum()) } }) }