initial commit
This commit is contained in:
134
examples/basic/service_test.go
Normal file
134
examples/basic/service_test.go
Normal file
@@ -0,0 +1,134 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"git.derfenix.pro/fenix/commander"
|
||||
"git.derfenix.pro/fenix/commander/inmemorycache"
|
||||
)
|
||||
|
||||
func BenchmarkServiceNoop(b *testing.B) {
|
||||
ctx := context.Background()
|
||||
|
||||
cmd := commander.New(10)
|
||||
|
||||
c1 := GetName{UID: uuid.NewString()}
|
||||
c2 := GetAddress{Input: &c1.Result}
|
||||
commands := []commander.Command{&c1, &c2}
|
||||
|
||||
b.ResetTimer()
|
||||
b.ReportAllocs()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
if err := cmd.Execute(ctx, "", commands...); err != nil {
|
||||
_ = err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkServiceWithDelay(b *testing.B) {
|
||||
ctx := context.Background()
|
||||
|
||||
cmd := commander.New(10)
|
||||
|
||||
c1 := GetName{UID: uuid.NewString(), Sleep: time.Microsecond * 100}
|
||||
c2 := GetAddress{Input: &c1.Result}
|
||||
commands := []commander.Command{&c1, &c2}
|
||||
|
||||
b.ResetTimer()
|
||||
b.ReportAllocs()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
if err := cmd.Execute(ctx, "", commands...); err != nil {
|
||||
_ = err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkServiceWithRollbackNoop(b *testing.B) {
|
||||
ctx := context.Background()
|
||||
|
||||
cmd := commander.New(10)
|
||||
|
||||
c1 := GetName{UID: uuid.NewString()}
|
||||
c2 := GetAddress{Input: &c1.Result}
|
||||
commands := []commander.Command{&c1, &c2}
|
||||
|
||||
commands = append(commands, &GetAddress{Input: &c2.Result})
|
||||
|
||||
b.ResetTimer()
|
||||
b.ReportAllocs()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
if err := cmd.Execute(ctx, "", commands...); err != nil {
|
||||
_ = err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkServiceWithRollbackWithDelay(b *testing.B) {
|
||||
ctx := context.Background()
|
||||
|
||||
cmd := commander.New(10)
|
||||
|
||||
c1 := GetName{UID: uuid.NewString(), Sleep: time.Microsecond * 100}
|
||||
c2 := GetAddress{Input: &c1.Result}
|
||||
commands := []commander.Command{&c1, &c2}
|
||||
|
||||
commands = append(commands, &GetAddress{Input: &c2.Result})
|
||||
|
||||
b.ResetTimer()
|
||||
b.ReportAllocs()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
if err := cmd.Execute(ctx, "", commands...); err != nil {
|
||||
_ = err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkServiceWithCacheNoop(b *testing.B) {
|
||||
ctx := context.Background()
|
||||
|
||||
cmd := commander.New(10)
|
||||
|
||||
cmd = cmd.WithCache(inmemorycache.NewInMemoryCache())
|
||||
|
||||
c1 := GetName{UID: uuid.NewString()}
|
||||
c2 := GetAddress{Input: &c1.Result}
|
||||
commands := []commander.Command{&c1, &c2}
|
||||
|
||||
b.ResetTimer()
|
||||
b.ReportAllocs()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
if err := cmd.Execute(ctx, "", commands...); err != nil {
|
||||
_ = err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkServiceWithCacheWithDelay(b *testing.B) {
|
||||
ctx := context.Background()
|
||||
|
||||
cmd := commander.New(10)
|
||||
|
||||
cmd = cmd.WithCache(inmemorycache.NewInMemoryCache())
|
||||
|
||||
c1 := GetName{UID: uuid.NewString(), Sleep: time.Microsecond * 100}
|
||||
c2 := GetAddress{Input: &c1.Result}
|
||||
commands := []commander.Command{&c1, &c2}
|
||||
|
||||
b.ResetTimer()
|
||||
b.ReportAllocs()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
if err := cmd.Execute(ctx, "", commands...); err != nil {
|
||||
_ = err
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user