Minor update
This commit is contained in:
		
							
								
								
									
										92
									
								
								core/service-status_bench_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								core/service-status_bench_test.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,92 @@ | |||||||
|  | package core | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"testing" | ||||||
|  | 	"time" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | var ( | ||||||
|  | 	firstCondition  = Condition("[STATUS] == 200") | ||||||
|  | 	secondCondition = Condition("[RESPONSE_TIME] < 500") | ||||||
|  | 	thirdCondition  = Condition("[CERTIFICATE_EXPIRATION] < 72h") | ||||||
|  |  | ||||||
|  | 	timestamp = time.Now() | ||||||
|  |  | ||||||
|  | 	testService = Service{ | ||||||
|  | 		Name:                    "name", | ||||||
|  | 		Group:                   "group", | ||||||
|  | 		URL:                     "https://example.org/what/ever", | ||||||
|  | 		Method:                  "GET", | ||||||
|  | 		Body:                    "body", | ||||||
|  | 		Interval:                30 * time.Second, | ||||||
|  | 		Conditions:              []*Condition{&firstCondition, &secondCondition, &thirdCondition}, | ||||||
|  | 		Alerts:                  nil, | ||||||
|  | 		Insecure:                false, | ||||||
|  | 		NumberOfFailuresInARow:  0, | ||||||
|  | 		NumberOfSuccessesInARow: 0, | ||||||
|  | 	} | ||||||
|  | 	testSuccessfulResult = Result{ | ||||||
|  | 		Hostname:              "example.org", | ||||||
|  | 		IP:                    "127.0.0.1", | ||||||
|  | 		HTTPStatus:            200, | ||||||
|  | 		Body:                  []byte("body"), | ||||||
|  | 		Errors:                nil, | ||||||
|  | 		Connected:             true, | ||||||
|  | 		Success:               true, | ||||||
|  | 		Timestamp:             timestamp, | ||||||
|  | 		Duration:              150 * time.Millisecond, | ||||||
|  | 		CertificateExpiration: 10 * time.Hour, | ||||||
|  | 		ConditionResults: []*ConditionResult{ | ||||||
|  | 			{ | ||||||
|  | 				Condition: "[STATUS] == 200", | ||||||
|  | 				Success:   true, | ||||||
|  | 			}, | ||||||
|  | 			{ | ||||||
|  | 				Condition: "[RESPONSE_TIME] < 500", | ||||||
|  | 				Success:   true, | ||||||
|  | 			}, | ||||||
|  | 			{ | ||||||
|  | 				Condition: "[CERTIFICATE_EXPIRATION] < 72h", | ||||||
|  | 				Success:   true, | ||||||
|  | 			}, | ||||||
|  | 		}, | ||||||
|  | 	} | ||||||
|  | 	testUnsuccessfulResult = Result{ | ||||||
|  | 		Hostname:              "example.org", | ||||||
|  | 		IP:                    "127.0.0.1", | ||||||
|  | 		HTTPStatus:            200, | ||||||
|  | 		Body:                  []byte("body"), | ||||||
|  | 		Errors:                []string{"error-1", "error-2"}, | ||||||
|  | 		Connected:             true, | ||||||
|  | 		Success:               false, | ||||||
|  | 		Timestamp:             timestamp, | ||||||
|  | 		Duration:              750 * time.Millisecond, | ||||||
|  | 		CertificateExpiration: 10 * time.Hour, | ||||||
|  | 		ConditionResults: []*ConditionResult{ | ||||||
|  | 			{ | ||||||
|  | 				Condition: "[STATUS] == 200", | ||||||
|  | 				Success:   true, | ||||||
|  | 			}, | ||||||
|  | 			{ | ||||||
|  | 				Condition: "[RESPONSE_TIME] < 500", | ||||||
|  | 				Success:   false, | ||||||
|  | 			}, | ||||||
|  | 			{ | ||||||
|  | 				Condition: "[CERTIFICATE_EXPIRATION] < 72h", | ||||||
|  | 				Success:   false, | ||||||
|  | 			}, | ||||||
|  | 		}, | ||||||
|  | 	} | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | func BenchmarkServiceStatus_WithResultPagination(b *testing.B) { | ||||||
|  | 	service := &testService | ||||||
|  | 	serviceStatus := NewServiceStatus(service) | ||||||
|  | 	for i := 0; i < MaximumNumberOfResults; i++ { | ||||||
|  | 		serviceStatus.AddResult(&testSuccessfulResult) | ||||||
|  | 	} | ||||||
|  | 	for n := 0; n < b.N; n++ { | ||||||
|  | 		serviceStatus.WithResultPagination(1, 20) | ||||||
|  | 	} | ||||||
|  | 	b.ReportAllocs() | ||||||
|  | } | ||||||
| @ -127,8 +127,11 @@ func BenchmarkStore_Insert(b *testing.B) { | |||||||
| 	for _, scenario := range scenarios { | 	for _, scenario := range scenarios { | ||||||
| 		b.Run(scenario.Name, func(b *testing.B) { | 		b.Run(scenario.Name, func(b *testing.B) { | ||||||
| 			for n := 0; n < b.N; n++ { | 			for n := 0; n < b.N; n++ { | ||||||
| 				scenario.Store.Insert(&testService, &testSuccessfulResult) | 				if n%100 == 0 { | ||||||
| 				scenario.Store.Insert(&testService, &testUnsuccessfulResult) | 					scenario.Store.Insert(&testService, &testSuccessfulResult) | ||||||
|  | 				} else { | ||||||
|  | 					scenario.Store.Insert(&testService, &testUnsuccessfulResult) | ||||||
|  | 				} | ||||||
| 			} | 			} | ||||||
| 			b.ReportAllocs() | 			b.ReportAllocs() | ||||||
| 		}) | 		}) | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user