Skip to content

Commit b60aadb

Browse files
committed
add test for changing maxBytesPerFile
1 parent 873f5c6 commit b60aadb

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

diskqueue_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,61 @@ func TestDiskQueueTorture(t *testing.T) {
420420
Equal(t, depth, read)
421421
}
422422

423+
func TestDiskQueueResize(t *testing.T) {
424+
l := NewTestLogger(t)
425+
dqName := "test_disk_queue_resize" + strconv.Itoa(int(time.Now().Unix()))
426+
tmpDir, err := ioutil.TempDir("", fmt.Sprintf("nsq-test-%d", time.Now().UnixNano()))
427+
if err != nil {
428+
panic(err)
429+
}
430+
defer os.RemoveAll(tmpDir)
431+
msg := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
432+
ml := int64(len(msg))
433+
dq := New(dqName, tmpDir, 8*(ml+4), int32(ml), 1<<10, 2500, time.Second, l)
434+
NotNil(t, dq)
435+
Equal(t, int64(0), dq.Depth())
436+
437+
for i := 0; i < 8; i++ {
438+
msg[0] = byte(i)
439+
err := dq.Put(msg)
440+
Nil(t, err)
441+
}
442+
Equal(t, int64(1), dq.(*diskQueue).writeFileNum)
443+
Equal(t, int64(0), dq.(*diskQueue).writePos)
444+
Equal(t, int64(8), dq.Depth())
445+
446+
dq.Close()
447+
dq = New(dqName, tmpDir, 10*(ml+4), int32(ml), 1<<10, 2500, time.Second, l)
448+
449+
for i := 0; i < 10; i++ {
450+
msg[0] = byte(20 + i)
451+
err := dq.Put(msg)
452+
Nil(t, err)
453+
}
454+
Equal(t, int64(2), dq.(*diskQueue).writeFileNum)
455+
Equal(t, int64(0), dq.(*diskQueue).writePos)
456+
Equal(t, int64(18), dq.Depth())
457+
458+
for i := 0; i < 8; i++ {
459+
msg[0] = byte(i)
460+
Equal(t, msg, <-dq.ReadChan())
461+
}
462+
for i := 0; i < 10; i++ {
463+
msg[0] = byte(20 + i)
464+
Equal(t, msg, <-dq.ReadChan())
465+
}
466+
Equal(t, int64(0), dq.Depth())
467+
dq.Close()
468+
469+
// make sure there aren't "bad" files due to read logic errors
470+
files, err := filepath.Glob(filepath.Join(tmpDir, dqName+"*.bad"))
471+
Nil(t, err)
472+
// empty files slice is actually nil, length check is less confusing
473+
if len(files) > 0 {
474+
Equal(t, []string{}, files)
475+
}
476+
}
477+
423478
func BenchmarkDiskQueuePut16(b *testing.B) {
424479
benchmarkDiskQueuePut(16, b)
425480
}

0 commit comments

Comments
 (0)