forked from DFanso/commit-msg
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateMsg_test.go
More file actions
48 lines (40 loc) · 1.14 KB
/
createMsg_test.go
File metadata and controls
48 lines (40 loc) · 1.14 KB
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
package cmd
import (
"context"
"sync"
"testing"
"github.com/dfanso/commit-msg/pkg/types"
)
// FakeProvider implements the llm.Provider interface to simulate API responses
type FakeProvider struct{}
func (f FakeProvider) Name() types.LLMProvider { return "fake" }
func (f FakeProvider) Generate(ctx context.Context, changes string, opts *types.GenerationOptions) (string, error) {
return "mock commit message", nil
}
func TestGenerateMessageRateLimiter(t *testing.T) {
ctx := context.Background()
var waitGroup sync.WaitGroup
successCount := 0
var mu sync.Mutex
// Test sending a number of messages in a short period to check the rate limiter
numCalls := 100
waitGroup.Add(numCalls)
for i := 0; i < numCalls; i++ {
go func() {
defer waitGroup.Done()
_, err := generateMessage(ctx, FakeProvider{}, "", nil)
if err != nil {
t.Logf("rate limiter error: %v", err)
return
}
mu.Lock()
successCount++
mu.Unlock()
}()
}
waitGroup.Wait()
t.Logf("Successful calls: %d out of %d", successCount, numCalls)
if successCount != numCalls {
t.Errorf("expected %d successful calls but got %d", numCalls, successCount)
}
}