forked from flow-hydraulics/flow-pds
-
Notifications
You must be signed in to change notification settings - Fork 2
/
benchmarkcreate_test.go
81 lines (68 loc) · 2.32 KB
/
benchmarkcreate_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"bytes"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"github.com/flow-hydraulics/flow-pds/service/common"
pds_http "github.com/flow-hydraulics/flow-pds/service/http"
flow "github.com/onflow/flow-go-sdk"
)
func benchmarkCreate(packs, slots uint, b *testing.B) {
cfg := getTestCfg(nil, b)
server, cleanup := getTestServer(cfg, false)
defer func() {
cleanup()
}()
addr := common.FlowAddress(flow.HexToAddress("0x1"))
collection := makeTestCollection(int(packs * slots))
dReq := pds_http.ReqCreateDistribution{
FlowID: common.FlowID{Int64: int64(1), Valid: true},
Issuer: addr,
PackTemplate: pds_http.ReqPackTemplate{
PackReference: pds_http.AddressLocation{
Name: "TestPackNFT",
Address: addr,
},
CollectibleReference: pds_http.AddressLocation{
Name: "TestCollectibleNFT",
Address: addr,
},
PackCount: packs,
Buckets: []pds_http.ReqBucket{
{
CollectibleCount: slots,
CollectibleCollection: collection,
},
},
},
}
jReq, err := json.Marshal(dReq)
if err != nil {
b.Fatal(err)
}
for n := 0; n < b.N; n++ {
req, err := http.NewRequest("POST", "/v1/distributions", bytes.NewBuffer(jReq))
if err != nil {
b.Fatal(err)
}
req.Header.Set("Content-Type", "application/json")
rr := httptest.NewRecorder()
server.Server.Handler.ServeHTTP(rr, req)
// Check the status code is what we expect.
if status := rr.Code; status != http.StatusCreated {
b.Errorf("handler returned wrong status code: got %v want %v", status, http.StatusCreated)
b.Log(rr.Body)
}
}
}
func BenchmarkCreate1Collectible(b *testing.B) { benchmarkCreate(1, 1, b) }
func BenchmarkCreate1kCollectibles(b *testing.B) { benchmarkCreate(100, 10, b) }
func BenchmarkCreate10kCollectibles(b *testing.B) { benchmarkCreate(1000, 10, b) }
func BenchmarkCreate20kCollectibles(b *testing.B) { benchmarkCreate(2000, 10, b) }
func BenchmarkCreate30kCollectibles(b *testing.B) { benchmarkCreate(3000, 10, b) }
func BenchmarkCreate40kCollectibles(b *testing.B) { benchmarkCreate(4000, 10, b) }
func BenchmarkCreate50kCollectibles(b *testing.B) { benchmarkCreate(5000, 10, b) }
func BenchmarkCreate100kCollectibles(b *testing.B) { benchmarkCreate(10000, 10, b) }
// func BenchmarkCreate1MCollectibles(b *testing.B) { benchmarkCreate(100000, 10, b) }