• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

looplab / eventhorizon / 22671292316

04 Mar 2026 01:24PM UTC coverage: 52.974% (-0.1%) from 53.091%
22671292316

Pull #433

github

web-flow
Merge c45e35d3d into 0a9fd8211
Pull Request #433: Upgrade golangci-lint to v2 and fix all lint issues

120 of 233 new or added lines in 49 files covered. (51.5%)

5 existing lines in 3 files now uncovered.

4319 of 8153 relevant lines covered (52.97%)

58.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/outbox/performance_testing.go
1
// Copyright (c) 2021 - The Event Horizon authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
package outbox
16

17
import (
18
        "context"
19
        "fmt"
20
        "math/rand/v2"
21
        "sync"
22
        "testing"
23
        "time"
24

25
        eh "github.com/looplab/eventhorizon"
26
        "github.com/looplab/eventhorizon/mocks"
27
        "github.com/looplab/eventhorizon/uuid"
28
)
29

30
func Benchmark(b *testing.B, o eh.Outbox) {
×
31
        numAggregates := 50
×
32
        numHandlers := 3
×
33
        numEvents := b.N
×
34

×
35
        b.Log("num iterations:", b.N)
×
36

×
37
        ctx, cancel := context.WithCancel(context.Background())
×
38

×
39
        handlers := make([]*mocks.EventHandler, numHandlers)
×
40
        for i := range handlers {
×
41
                h := mocks.NewEventHandler(fmt.Sprintf("handler-%d", i))
×
42

×
43
                if err := o.AddHandler(context.Background(), eh.MatchAll{}, h); err != nil {
×
44
                        b.Fatal("there should be no error:", err)
×
45
                }
×
46

47
                handlers[i] = h
×
48
        }
49

50
        var wg sync.WaitGroup
×
51
        for _, h := range handlers {
×
52
                wg.Add(1)
×
53

×
54
                go func(h *mocks.EventHandler) {
×
55
                        defer wg.Done()
×
56

×
57
                        numEventsReceived := 0
×
58

×
59
                        for {
×
60
                                if numEventsReceived == numEvents {
×
61
                                        return
×
62
                                }
×
63
                                select {
×
64
                                case <-h.Recv:
×
65
                                        numEventsReceived++
×
66

×
67
                                        continue
×
68
                                case <-ctx.Done():
×
69
                                        return
×
70
                                case <-time.After(30 * time.Second):
×
71
                                        b.Error("did not receive message within timeout")
×
72

×
73
                                        return
×
74
                                }
75
                        }
76
                }(h)
77
        }
78

79
        var aggregates []*struct {
×
80
                id      uuid.UUID
×
81
                version int
×
82
        }
×
83

×
NEW
84
        for range numAggregates {
×
85
                aggregates = append(aggregates, &struct {
×
86
                        id      uuid.UUID
×
87
                        version int
×
88
                }{uuid.New(), 0})
×
89
        }
×
90

91
        b.Log("setup complete")
×
92
        b.ResetTimer()
×
93

×
NEW
94
        for n := range numEvents {
×
NEW
95
                a := aggregates[rand.IntN(len(aggregates))] //nolint:gosec
×
96
                a.version++
×
97

×
98
                timestamp := time.Date(2009, time.November, 10, 23, n, 0, 0, time.UTC)
×
99
                e := eh.NewEvent(
×
100
                        mocks.EventType, &mocks.EventData{Content: fmt.Sprintf("event%d", n)}, timestamp,
×
101
                        eh.ForAggregate(mocks.AggregateType, a.id, a.version))
×
102

×
103
                if err := o.HandleEvent(context.Background(), e); err != nil {
×
104
                        b.Error("could not handle event:", err)
×
105
                }
×
106
        }
107

108
        wg.Wait() // Wait for all events to be handled.
×
109
        b.StopTimer()
×
110
        cancel() // Stop handler goroutines.
×
111

×
112
        checkOutboxBenchErrors(b, o)
×
113
}
114

115
func checkOutboxBenchErrors(b *testing.B, o eh.Outbox) {
×
116
        b.Helper()
×
117

×
118
        for {
×
119
                select {
×
120
                case err := <-o.Errors():
×
121
                        if err != nil {
×
122
                                b.Error("there should be no previous error:", err)
×
123
                        }
×
124
                default:
×
125
                        return
×
126
                }
127
        }
128
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc