Browse Source

Fix benchmarktests (#557)

Kjell Kvinge 2 years ago
parent
commit
4b0974ec10
1 changed files with 17 additions and 13 deletions
  1. 17 13
      models/graph_test.go

+ 17 - 13
models/graph_test.go

@@ -17,25 +17,29 @@ func BenchmarkGetCommitGraph(b *testing.B) {
17 17
 		b.Error("Could not open repository")
18 18
 	}
19 19
 
20
-	graph, err := GetCommitGraph(currentRepo)
21
-	if err != nil {
22
-		b.Error("Could get commit graph")
23
-	}
24
-
25
-	if len(graph) < 100 {
26
-		b.Error("Should get 100 log lines.")
20
+	for i := 0; i < b.N; i++ {
21
+		graph, err := GetCommitGraph(currentRepo)
22
+		if err != nil {
23
+			b.Error("Could get commit graph")
24
+		}
25
+
26
+		if len(graph) < 100 {
27
+			b.Error("Should get 100 log lines.")
28
+		}
27 29
 	}
28 30
 }
29 31
 
30 32
 func BenchmarkParseCommitString(b *testing.B) {
31 33
 	testString := "* DATA:||4e61bacab44e9b4730e44a6615d04098dd3a8eaf|2016-12-20 21:10:41 +0100|Kjell Kvinge|kjell@kvinge.biz|4e61bac|Add route for graph"
32 34
 
33
-	graphItem, err := graphItemFromString(testString, nil)
34
-	if err != nil {
35
-		b.Error("could not parse teststring")
36
-	}
35
+	for i := 0; i < b.N; i++ {
36
+		graphItem, err := graphItemFromString(testString, nil)
37
+		if err != nil {
38
+			b.Error("could not parse teststring")
39
+		}
37 40
 
38
-	if graphItem.Author != "Kjell Kvinge" {
39
-		b.Error("Did not get expected data")
41
+		if graphItem.Author != "Kjell Kvinge" {
42
+			b.Error("Did not get expected data")
43
+		}
40 44
 	}
41 45
 }