cmd/coordinator: use time.UTC explicitly in tests

Also use the name “now” for both the Created and Expires fields on the
remoteBuildlet message, to avoid unnecessary (and mysterious) skew if
the call happens to span a second boundary.

This fixes TestHandleBuildetCreate_Stream and
TestHandleBuildetCreate_PreStream when run on a machine with a non-UTC
local time zone.

Change-Id: I507185c758bc4fc8b1c45e181a278816ee77a337
Reviewed-on: https://go-review.googlesource.com/c/build/+/208659
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/cmd/coordinator/remote.go b/cmd/coordinator/remote.go
index d134d44..effa66c 100644
--- a/cmd/coordinator/remote.go
+++ b/cmd/coordinator/remote.go
@@ -200,13 +200,14 @@
 			st := sched.waiterState(si)
 			sendJSONLine(msg{Status: &st})
 		case bc := <-resc:
+			now := timeNow()
 			rb := &remoteBuildlet{
 				User:        user,
 				BuilderType: builderType,
 				HostType:    bconf.HostType,
 				buildlet:    bc,
-				Created:     timeNow(),
-				Expires:     timeNow().Add(remoteBuildletIdleTimeout),
+				Created:     now,
+				Expires:     now.Add(remoteBuildletIdleTimeout),
 			}
 			rb.Name = addRemoteBuildlet(rb)
 			bc.SetName(rb.Name)
diff --git a/cmd/coordinator/remote_test.go b/cmd/coordinator/remote_test.go
index b4264f6..13236cd 100644
--- a/cmd/coordinator/remote_test.go
+++ b/cmd/coordinator/remote_test.go
@@ -129,7 +129,7 @@
 		removeBuilder(buildName)
 		testPoolHook = nil
 	}()
-	timeNow = func() time.Time { return time.Unix(123, 0) }
+	timeNow = func() time.Time { return time.Unix(123, 0).In(time.UTC) }
 	data := url.Values{}
 	data.Set("version", "20160922")
 	data.Set("builderType", buildName)
@@ -158,7 +158,7 @@
 		removeBuilder(buildName)
 		testPoolHook = nil
 	}()
-	timeNow = func() time.Time { return time.Unix(123, 0) }
+	timeNow = func() time.Time { return time.Unix(123, 0).In(time.UTC) }
 	data := url.Values{}
 	data.Set("version", buildlet.GomoteCreateStreamVersion)
 	data.Set("builderType", buildName)