Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for non-default time zones on Windows #897

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions integration_test/ops_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -835,13 +835,13 @@ func TestCustomLogFormat(t *testing.T) {
t.Fatal(err)
}

// When not using UTC timestamps, the parsing with "%Y-%m-%dT%H:%M:%S.%L%z" doesn't work
// correctly in windows (b/218888265).
line := fmt.Sprintf("<13>1 %s %s my_app_id - - - qqqqrrrr\n", time.Now().UTC().Format(time.RFC3339Nano), vm.Name)
zone := time.FixedZone("UTC-8", int((-8 * time.Hour).Seconds()))
line := fmt.Sprintf("<13>1 %s %s my_app_id - - - qqqqrrrr\n", time.Now().In(zone).Format(time.RFC3339Nano), vm.Name)
if err := gce.UploadContent(ctx, logger, vm, strings.NewReader(line), logPath); err != nil {
t.Fatalf("error writing dummy log line: %v", err)
}

// window (1 hour) is *less than* the time zone UTC offset (8 hours) to catch time zone parse failures
if err := gce.WaitForLog(ctx, logger.ToMainLog(), vm, "mylog_source", time.Hour, "jsonPayload.message=qqqqrrrr AND jsonPayload.ident=my_app_id"); err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -1611,6 +1611,41 @@ func TestWindowsEventLog(t *testing.T) {
})
}

func TestWindowsEventLogWithNonDefaultTimeZone(t *testing.T) {
t.Parallel()
gce.RunForEachPlatform(t, func(t *testing.T, platform string) {
t.Parallel()
if !gce.IsWindows(platform) {
t.SkipNow()
}
ctx, logger, vm := agents.CommonSetup(t, platform)
if _, err := gce.RunRemotely(ctx, logger.ToMainLog(), vm, "", `Set-TimeZone -Id "Eastern Standard Time"`); err != nil {
t.Fatal(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the new windows VM default time zone is just the same as Eastern Time. Does the VM created with zone us-east1 default to have Eastern Time?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the default time zone is already Eastern Time then this command is a no-op and the test should still fail as expected.

In my testing the VM time zone was always UTC regardless of which Cloud zone it was created in.

}
if err := setupOpsAgent(ctx, logger, vm, ""); err != nil {
t.Fatal(err)
}

// Write an event and record its approximate time
testMessage := "TestWindowsEventLogWithNonDefaultTimeZone"
if err := writeToSystemLog(ctx, logger.ToMainLog(), vm, testMessage); err != nil {
t.Fatal(err)
}
eventTime := time.Now()

// Validate that the log written to Cloud Logging has a timestamp that's
// close to eventTime. Use 24*time.Hour to cover all possible time zones.
logEntry, err := gce.QueryLog(ctx, logger.ToMainLog(), vm, "windows_event_log", 24*time.Hour, logMessageQueryForPlatform(platform, testMessage), gce.QueryMaxAttempts)
if err != nil {
t.Fatal(err)
}
timeDiff := eventTime.Sub(logEntry.Timestamp).Abs()
if timeDiff.Minutes() > 5 {
t.Fatalf("timestamp differs by %v minutes", timeDiff.Minutes())
}
})
}

func TestSystemdLog(t *testing.T) {
t.Parallel()
gce.RunForEachPlatform(t, func(t *testing.T, platform string) {
Expand Down