Skip to content

Commit

Permalink
add test for read EOF
Browse files Browse the repository at this point in the history
  • Loading branch information
mreiferson committed Oct 30, 2023
1 parent 92a60a5 commit 879d93e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions diskqueue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,3 +817,33 @@ func TestDiskQueueRollAsync(t *testing.T) {
return err
})
}

func TestWriteRollReadEOF(t *testing.T) {
l := NewTestLogger(t)
dqName := "test_disk_queue_roll_readEOF" + strconv.Itoa(int(time.Now().Unix()))
tmpDir, err := ioutil.TempDir("", fmt.Sprintf("nsq-test-%d", time.Now().UnixNano()))
if err != nil {
panic(err)
}
defer os.RemoveAll(tmpDir)
dq := New(dqName, tmpDir, 1024, 4, 1<<10, 2500, 2*time.Second, l)
defer dq.Close()
NotNil(t, dq)
Equal(t, int64(0), dq.Depth())

for i := 0; i < 205; i++ { // 204 messages fit, but message 205 will be too big
msg := []byte(fmt.Sprintf("%05d", i)) // 5 bytes
err = dq.Put(msg)

msgOut := <-dq.ReadChan()
Equal(t, msg, msgOut)
}

filepath.Walk(tmpDir, func(path string, info fs.FileInfo, err error) error {
if strings.HasSuffix(path, ".bad") {
t.FailNow()
}

return err
})
}

0 comments on commit 879d93e

Please sign in to comment.