diff --git a/queue_test.go b/queue_test.go index f1a714c..7e2a8ba 100644 --- a/queue_test.go +++ b/queue_test.go @@ -400,3 +400,32 @@ func TestQueueCorruptedWritingFile(t *testing.T) { var e entry.Entry require.False(t, q.Dequeue(&e)) } + +func TestQueueReopen(t *testing.T) { + dataDir := filepath.Join(tmpDir, "pqueue_reopen") + _ = os.RemoveAll(dataDir) + err := os.MkdirAll(dataDir, 0o777) + require.NoError(t, err) + defer func() { + _ = os.RemoveAll(dataDir) + }() + + q, err := New(dataDir, 3) + require.NoError(t, err) + + require.NoError(t, q.Enqueue([]byte{1, 2, 3})) + + var e entry.Entry + require.True(t, q.Dequeue(&e)) + require.EqualValues(t, e, []byte{1, 2, 3}) + + err = q.Close() + require.NoError(t, err) + + q, err = New(dataDir, 3) + require.NoError(t, err) + + // only one value was enqueued and it was already dequeued, so there shouldn't be anything else + require.False(t, q.Dequeue(&e)) + q.Close() +} diff --git a/utils.go b/utils.go index 242be73..b885bbd 100644 --- a/utils.go +++ b/utils.go @@ -59,7 +59,7 @@ func loadFileInfos(dir string, infoExtractor func(os.DirEntry) (os.FileInfo, err files := make([]file, 0, len(fileList)) for i := range fileList { - if strings.HasPrefix(fileList[i].Name(), segPrefix) { + if strings.HasPrefix(fileList[i].Name(), segPrefix) && !strings.HasSuffix(fileList[i].Name(), segOffsetFileSuffix) { info, e := infoExtractor(fileList[i]) if e != nil { return nil, e