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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « client/cmd/isolate/isolate_event_logger.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/cmd/isolate/isolate_event_logger_test.go
diff --git a/client/cmd/isolate/isolate_event_logger_test.go b/client/cmd/isolate/isolate_event_logger_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..41a83754d56c4ca109f7748b2d6cd3d6772009ac
--- /dev/null
+++ b/client/cmd/isolate/isolate_event_logger_test.go
@@ -0,0 +1,96 @@
+// Copyright 2017 The LUCI Authors. All rights reserved.
+// Use of this source code is governed under the Apache License, Version 2.0
+// that can be found in the LICENSE file.
+
+package main
+
+import (
+ "fmt"
+ "reflect"
+ "testing"
+ "time"
+
+ "golang.org/x/net/context"
+
+ "github.com/golang/protobuf/proto"
+ "github.com/luci/luci-go/common/eventlog"
+ logpb "github.com/luci/luci-go/common/eventlog/proto"
+)
+
+// fakeLogger implements syncLogger by storing method arguments for later inspection.
+type fakeLogger struct {
+ events []*eventlog.ChromeInfraLogEvent
+}
+
+func (fl *fakeLogger) LogSync(ctx context.Context, events ...*eventlog.ChromeInfraLogEvent) error {
+ fl.events = append(fl.events, events...)
+ return nil
+}
+
+func defaultEvent() *eventlog.ChromeInfraLogEvent {
+ point := logpb.ChromeInfraEvent_POINT
+ return &eventlog.ChromeInfraLogEvent{
+ LogEvent: &logpb.LogRequestLite_LogEventLite{
+ EventTimeMs: proto.Int64(10),
+ },
+ InfraEvent: &logpb.ChromeInfraEvent{
+ TimestampKind: &point,
+ },
+ }
+}
+
+func (fl *fakeLogger) NewLogEvent(ctx context.Context, eventTime eventlog.TypedTime) *eventlog.ChromeInfraLogEvent {
+ return defaultEvent()
+}
+
+func fakeGetEnvValue(key string) *string {
+ if key == "" {
+ return nil
+ }
+
+ ret := fmt.Sprintf("%s value", key)
+ return &ret
+}
+
+func TestLogSync(t *testing.T) {
+ flogger := &fakeLogger{}
+ eventlogger := &IsolateEventLogger{client: flogger, getEnvironmentValue: fakeGetEnvValue}
+ ctx := context.Background()
+ op := logpb.IsolateClientEvent_ARCHIVE.Enum()
+ const startUsec = 100
+ const endUsec = 200
+ start := time.Unix(0, startUsec*1000)
+ end := time.Unix(0, endUsec*1000)
+
+ details := &logpb.IsolateClientEvent_ArchiveDetails{
+ HitCount: proto.Int64(1),
+ MissCount: proto.Int64(2),
+ HitBytes: proto.Int64(4),
+ MissBytes: proto.Int64(8),
+ IsolateHash: []string{"hash brown"},
+ }
+
+ wantEvent := defaultEvent()
+ wantEvent.InfraEvent.IsolateClientEvent = &logpb.IsolateClientEvent{
+ Binary: &logpb.Binary{
+ Name: proto.String("isolate"),
+ VersionNumber: proto.String(version),
+ },
+ Operation: op,
+ ArchiveDetails: details,
+ Master: proto.String("BUILDBOT_MASTERNAME value"),
+ Builder: proto.String("BUILDBOT_BUILDERNAME value"),
+ BuildId: proto.String("BUILDBOT_BUILDNUMBER value"),
+ Slave: proto.String("BUILDBOT_SLAVENAME value"),
+ StartTsUsec: proto.Int64(startUsec),
+ EndTsUsec: proto.Int64(endUsec),
+ }
+
+ err := eventlogger.logStats(ctx, op, start, end, details)
+ if err != nil {
+ t.Fatalf("IsolateEventLogger.logStats: got err %v; want %v", err, nil)
+ }
+ if got, want := flogger.events, []*eventlog.ChromeInfraLogEvent{wantEvent}; !reflect.DeepEqual(got, want) {
+ t.Errorf("IsolateEventLogger.logStats: got %v; want %v", got, want)
+ }
+}
« 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