diff options
| author | Chris Lu <chris.lu@gmail.com> | 2020-08-22 16:33:00 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2020-08-22 16:33:00 -0700 |
| commit | 5e6b714836a365852378c117e48d6228ce925538 (patch) | |
| tree | cf333abdf46fc15c8c482b352fb1851173799f0b | |
| parent | 42ddbcc3a2d08272b62cef636b62bf439dd5c627 (diff) | |
| download | seaweedfs-5e6b714836a365852378c117e48d6228ce925538.tar.xz seaweedfs-5e6b714836a365852378c117e48d6228ce925538.zip | |
add random test
| -rw-r--r-- | weed/filesys/dirty_page_interval_test.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/weed/filesys/dirty_page_interval_test.go b/weed/filesys/dirty_page_interval_test.go index ab3b37b7c..57da01bc3 100644 --- a/weed/filesys/dirty_page_interval_test.go +++ b/weed/filesys/dirty_page_interval_test.go @@ -2,6 +2,7 @@ package filesys import ( "bytes" + "math/rand" "testing" ) @@ -66,6 +67,29 @@ func TestContinuousIntervals_RealCase1(t *testing.T) { } +func TestRandomWrites(t *testing.T) { + + c := &ContinuousIntervals{} + + data := make([]byte, 1024) + + for i:=0;i<1024;i++ { + + start, stop := rand.Intn(len(data)), rand.Intn(len(data)) + if start > stop { + start,stop = stop, start + } + + rand.Read(data[start:stop+1]) + + c.AddInterval(data[start:stop+1], int64(start)) + + expectedData(t, c, 0, data...) + + } + +} + func expectedData(t *testing.T, c *ContinuousIntervals, offset int, data ...byte) { start, stop := int64(offset), int64(offset+len(data)) for _, list := range c.lists { |
