Skip to content

Commit 637281a

Browse files
committed
add failing TestDiskQueueRollAsync
1 parent cc41549 commit 637281a

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

diskqueue_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import (
44
"bufio"
55
"bytes"
66
"fmt"
7+
"io/fs"
78
"io/ioutil"
89
"os"
910
"path"
1011
"path/filepath"
1112
"reflect"
1213
"runtime"
1314
"strconv"
15+
"strings"
1416
"sync"
1517
"sync/atomic"
1618
"testing"
@@ -773,3 +775,39 @@ func benchmarkDiskQueueGet(size int64, b *testing.B) {
773775
<-dq.ReadChan()
774776
}
775777
}
778+
779+
func TestDiskQueueRollAsync(t *testing.T) {
780+
l := NewTestLogger(t)
781+
dqName := "test_disk_queue_roll" + strconv.Itoa(int(time.Now().Unix()))
782+
tmpDir, err := ioutil.TempDir("", fmt.Sprintf("nsq-test-%d", time.Now().UnixNano()))
783+
if err != nil {
784+
panic(err)
785+
}
786+
defer os.RemoveAll(tmpDir)
787+
msg := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}
788+
ml := int64(len(msg))
789+
dq := New(dqName, tmpDir, 10*(ml+4), int32(ml), 1<<10, 2500, 2*time.Second, l)
790+
defer dq.Close()
791+
NotNil(t, dq)
792+
Equal(t, int64(0), dq.Depth())
793+
794+
for i := 0; i < 11; i++ {
795+
err := dq.Put(msg)
796+
Nil(t, err)
797+
Equal(t, int64(1), dq.Depth())
798+
799+
Equal(t, msg, <-dq.ReadChan())
800+
Equal(t, int64(0), dq.Depth())
801+
}
802+
803+
Equal(t, int64(1), dq.(*diskQueue).writeFileNum)
804+
Equal(t, int64(ml+4), dq.(*diskQueue).writePos)
805+
806+
filepath.Walk(tmpDir, func(path string, info fs.FileInfo, err error) error {
807+
if strings.HasSuffix(path, ".bad") {
808+
t.FailNow()
809+
}
810+
811+
return err
812+
})
813+
}

0 commit comments

Comments
 (0)