Skip to content

Added test for reproduction of rolling failure #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions diskqueue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import (
"bufio"
"bytes"
"fmt"
"io/fs"
"io/ioutil"
"os"
"path"
"path/filepath"
"reflect"
"runtime"
"strconv"
"strings"
"sync"
"sync/atomic"
"testing"
Expand Down Expand Up @@ -130,6 +132,42 @@ func TestDiskQueueRoll(t *testing.T) {
}
}

func TestDiskQueueRollAsync(t *testing.T) {
l := NewTestLogger(t)
dqName := "test_disk_queue_roll" + 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)
msg := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}
ml := int64(len(msg))
dq := New(dqName, tmpDir, 10*(ml+4), int32(ml), 1<<10, 2500, 2*time.Second, l)
defer dq.Close()
NotNil(t, dq)
Equal(t, int64(0), dq.Depth())

for i := 0; i < 11; i++ {
err := dq.Put(msg)
Nil(t, err)
Equal(t, int64(1), dq.Depth())

Equal(t, msg, <-dq.ReadChan())
Equal(t, int64(0), dq.Depth())
}

Equal(t, int64(1), dq.(*diskQueue).writeFileNum)
Equal(t, int64(ml+4), dq.(*diskQueue).writePos)

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also t.Logf() something here, like "found .bad chunk: ${path}"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure I can add this when I have some time but anyway this is just a draft PR not meant to be merged until the bug itself is fixed, it's a kinda TDD-approach to repro/prove there is a problem ;)

}

return err
})
}

func TestDiskQueuePeek(t *testing.T) {
l := NewTestLogger(t)
dqName := "test_disk_queue_peek" + strconv.Itoa(int(time.Now().Unix()))
Expand Down