-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathgithub_telemetry_e2e_test.go
More file actions
68 lines (58 loc) · 1.9 KB
/
Copy pathgithub_telemetry_e2e_test.go
File metadata and controls
68 lines (58 loc) · 1.9 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package e2e
import (
"sync"
"testing"
"time"
copilot "github.com/github/copilot-sdk/go"
"github.com/github/copilot-sdk/go/internal/e2e/testharness"
"github.com/github/copilot-sdk/go/rpc"
)
func TestGitHubTelemetryE2E(t *testing.T) {
t.Run("should forward github telemetry for a live session", func(t *testing.T) {
ctx := testharness.NewTestContext(t)
ctx.ConfigureForTest(t)
var mu sync.Mutex
var notifications []*rpc.GitHubTelemetryNotification
client := ctx.NewClient(func(opts *copilot.ClientOptions) {
opts.OnGitHubTelemetry = func(notification *rpc.GitHubTelemetryNotification) {
mu.Lock()
notifications = append(notifications, notification)
mu.Unlock()
}
})
t.Cleanup(func() { client.ForceStop() })
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
})
if err != nil {
t.Fatalf("CreateSession failed: %v", err)
}
t.Cleanup(func() { session.Disconnect() })
notification := waitForGitHubTelemetryNotification(t, &mu, ¬ifications, 30*time.Second)
if notification.SessionID == nil || *notification.SessionID == "" {
t.Fatal("Expected a non-empty SessionID")
}
if notification.Event.Kind == "" {
t.Fatal("Expected a non-empty Event.Kind")
}
})
}
func waitForGitHubTelemetryNotification(t *testing.T, mu *sync.Mutex, notifications *[]*rpc.GitHubTelemetryNotification, timeout time.Duration) *rpc.GitHubTelemetryNotification {
t.Helper()
deadline := time.Now().Add(timeout)
for time.Now().Before(deadline) {
mu.Lock()
if len(*notifications) > 0 {
notification := (*notifications)[0]
mu.Unlock()
if notification != nil {
return notification
}
t.Fatal("Received nil GitHub telemetry notification")
}
mu.Unlock()
time.Sleep(50 * time.Millisecond)
}
t.Fatalf("Timed out waiting for GitHub telemetry notification after %s", timeout)
return nil
}