Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Side by Side Diff: client/cmd/isolate/isolate_event_logger_test.go

Issue 2918043003: Log eventlogs from legacy isolate archive command (Closed)
Patch Set: Address review comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « client/cmd/isolate/isolate_event_logger.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package main
6
7 import (
8 "fmt"
9 "reflect"
10 "testing"
11 "time"
12
13 "golang.org/x/net/context"
14
15 "github.com/golang/protobuf/proto"
16 "github.com/luci/luci-go/common/eventlog"
17 logpb "github.com/luci/luci-go/common/eventlog/proto"
18 )
19
20 // fakeLogger implements syncLogger by storing method arguments for later inspec tion.
21 type fakeLogger struct {
22 events []*eventlog.ChromeInfraLogEvent
23 }
24
25 func (fl *fakeLogger) LogSync(ctx context.Context, events ...*eventlog.ChromeInf raLogEvent) error {
26 fl.events = append(fl.events, events...)
27 return nil
28 }
29
30 func defaultEvent() *eventlog.ChromeInfraLogEvent {
31 point := logpb.ChromeInfraEvent_POINT
32 return &eventlog.ChromeInfraLogEvent{
33 LogEvent: &logpb.LogRequestLite_LogEventLite{
34 EventTimeMs: proto.Int64(10),
35 },
36 InfraEvent: &logpb.ChromeInfraEvent{
37 TimestampKind: &point,
38 },
39 }
40 }
41
42 func (fl *fakeLogger) NewLogEvent(ctx context.Context, eventTime eventlog.TypedT ime) *eventlog.ChromeInfraLogEvent {
43 return defaultEvent()
44 }
45
46 func fakeGetEnvValue(key string) *string {
47 if key == "" {
48 return nil
49 }
50
51 ret := fmt.Sprintf("%s value", key)
52 return &ret
53 }
54
55 func TestLogSync(t *testing.T) {
56 flogger := &fakeLogger{}
57 eventlogger := &IsolateEventLogger{client: flogger, getEnvironmentValue: fakeGetEnvValue}
58 ctx := context.Background()
59 op := logpb.IsolateClientEvent_ARCHIVE.Enum()
60 const startUsec = 100
61 const endUsec = 200
62 start := time.Unix(0, startUsec*1000)
63 end := time.Unix(0, endUsec*1000)
64
65 details := &logpb.IsolateClientEvent_ArchiveDetails{
66 HitCount: proto.Int64(1),
67 MissCount: proto.Int64(2),
68 HitBytes: proto.Int64(4),
69 MissBytes: proto.Int64(8),
70 IsolateHash: []string{"hash brown"},
71 }
72
73 wantEvent := defaultEvent()
74 wantEvent.InfraEvent.IsolateClientEvent = &logpb.IsolateClientEvent{
75 Binary: &logpb.Binary{
76 Name: proto.String("isolate"),
77 VersionNumber: proto.String(version),
78 },
79 Operation: op,
80 ArchiveDetails: details,
81 Master: proto.String("BUILDBOT_MASTERNAME value"),
82 Builder: proto.String("BUILDBOT_BUILDERNAME value"),
83 BuildId: proto.String("BUILDBOT_BUILDNUMBER value"),
84 Slave: proto.String("BUILDBOT_SLAVENAME value"),
85 StartTsUsec: proto.Int64(startUsec),
86 EndTsUsec: proto.Int64(endUsec),
87 }
88
89 err := eventlogger.logStats(ctx, op, start, end, details)
90 if err != nil {
91 t.Fatalf("IsolateEventLogger.logStats: got err %v; want %v", err , nil)
92 }
93 if got, want := flogger.events, []*eventlog.ChromeInfraLogEvent{wantEven t}; !reflect.DeepEqual(got, want) {
94 t.Errorf("IsolateEventLogger.logStats: got %v; want %v", got, wa nt)
95 }
96 }
OLDNEW
« no previous file with comments | « client/cmd/isolate/isolate_event_logger.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698