Skip to content

Commit

Permalink
Restore some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jchiu255 committed May 3, 2017
1 parent 92c6b60 commit d951b29
Show file tree
Hide file tree
Showing 2 changed files with 295 additions and 291 deletions.
62 changes: 33 additions & 29 deletions badger/compact_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,35 +79,39 @@ func TestCompactLogBasic(t *testing.T) {
}

// TODO: Fix test. There seems to be some compaction being undone which is unexpected.
//func TestCompactLogUnclosedIter(t *testing.T) {
// // Create unclosed iterators. This will leave a lot of files in the directory.
// // Then re-open the database and check that everything is cleanup.
// ctx := context.Background()
// dir, err := ioutil.TempDir("/tmp", "badger")
// require.NoError(t, err)
// defer os.RemoveAll(dir)
func TestCompactLogUnclosedIter(t *testing.T) {
// Create unclosed iterators. This will leave a lot of files in the directory.
// Then re-open the database and check that everything is cleanup.
ctx := context.Background()
dir, err := ioutil.TempDir("/tmp", "badger")
require.NoError(t, err)
defer os.RemoveAll(dir)

// opt := getTestOptions(dir)
// var summary *Summary
// {
// kv := NewKV(opt)
// n := 5000
// for i := 0; i < n; i++ {
// if (i % 1000) == 0 {
// fmt.Printf("Putting i=%d\n", i)
// kv.NewIterator(ctx, 2, 1, false) // NOTE: Hold reference for test.
// }
// k := []byte(fmt.Sprintf("%16x", rand.Int63()))
// require.NoError(t, kv.Put(ctx, k, k))
// }
// // Don't close kv.
// summary = kv.lc.getSummary()
// }
iterOpt := IteratorOptions{}
iterOpt.FetchValues = true
iterOpt.PrefetchSize = 10

// // Make sure our test makes sense. There should be dirty files.
// require.True(t, len(summary.fileIDs) < len(getIDMap(dir)))
opt := getTestOptions(dir)
var summary *Summary
{
kv := NewKV(opt)
n := 5000
for i := 0; i < n; i++ {
if (i % 1000) == 0 {
fmt.Printf("Putting i=%d\n", i)
kv.NewIterator(iterOpt) // NOTE: Hold reference for test.
}
k := []byte(fmt.Sprintf("%16x", rand.Int63()))
require.NoError(t, kv.Put(ctx, k, k))
}
// Don't close kv.
summary = kv.lc.getSummary()
}

// kv := NewKV(opt) // This should clean up.
// summary2 := kv.lc.getSummary()
// require.Len(t, summary.fileIDs, len(summary2.fileIDs))
//}
// Make sure our test makes sense. There should be dirty files.
require.True(t, len(summary.fileIDs) < len(getIDMap(dir)))

kv := NewKV(opt) // This should clean up.
summary2 := kv.lc.getSummary()
require.Len(t, summary.fileIDs, len(summary2.fileIDs))
}
Loading

0 comments on commit d951b29

Please sign in to comment.