Parcourir la source

Memory tests. go test -v will show mmap being used on files of increased RAM size, in multiples of 128 Mbytes.

Gwyneth Llewelyn il y a 7 ans
Parent
commit
0ae1302925
1 fichiers modifiés avec 17 ajouts et 10 suppressions
  1. 17 10
      gosl_test.go

+ 17 - 10
gosl_test.go

@@ -4,18 +4,25 @@ import "os"
 import "testing"
 import "github.com/dgraph-io/badger/y"
 
-var Size int64 = 256 * 1024 * 1024
+var Size int64 = 128 * 1024 * 1024
 
 func TestMmap(t *testing.T) {
 	t.Log("Trying mmap")
-	flags := os.O_RDWR | os.O_CREATE | os.O_EXCL
-	f, err := os.OpenFile("test.md", flags, 0666)
-	defer f.Close()
-	y.Check(err)
-//	size := int64(256 * 1024 * 1024)
-	t.Logf("Size is : %v", Size)
-	_, err = y.Mmap(f,false,Size)
-	if err != nil {
-		t.Errorf("mmap failed with error: %v", err)
+	var i int64
+	for i = 1; i < 8; i++ {
+		flags := os.O_RDWR | os.O_CREATE | os.O_EXCL
+		f, err := os.OpenFile("test.md", flags, 0666)
+		defer f.Close()
+		y.Check(err)
+	//	size := int64(256 * 1024 * 1024)
+		t.Logf("Size is : %v", i*Size)
+		_, err = y.Mmap(f,false,i*Size)
+		if err != nil {
+			t.Errorf("mmap failed with error: %v", err)
+		}
+		err = os.Remove("test.md")
+		if err != nil {
+			t.Errorf("could not remove test.md: %v", err)
+		}
 	}
 }