integ-cli: fix clock skew against remote test daemon

This fixes the `docker events`-related tests as they have been
failing due to clock skew between CI machine and test daemon on
some other machine (even 1-2 seconds of diff causes races as
we pass local time to --since/--until).

If we're running in same host, we keep using time.Now(), otherwise
we read the system time of the daemon from `/info` endpoint.

Fixes pretty much all events-related tests on windows CI.

Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
This commit is contained in:
Ahmet Alp Balkan
2015-03-11 10:28:56 -07:00
parent d010bf0d99
commit e424c54d9c
4 changed files with 47 additions and 26 deletions
+26
View File
@@ -981,6 +981,32 @@ func readContainerFileWithExec(containerId, filename string) ([]byte, error) {
return []byte(out), err
}
// daemonTime provides the current time on the daemon host
func daemonTime(t *testing.T) time.Time {
if isLocalDaemon {
return time.Now()
}
body, err := sockRequest("GET", "/info", nil)
if err != nil {
t.Fatal("daemonTime: failed to get /info: %v", err)
}
type infoJSON struct {
SystemTime string
}
var info infoJSON
if err = json.Unmarshal(body, &info); err != nil {
t.Fatalf("unable to unmarshal /info response: %v", err)
}
dt, err := time.Parse(time.RFC3339Nano, info.SystemTime)
if err != nil {
t.Fatal(err)
}
return dt
}
func setupRegistry(t *testing.T) func() {
testRequires(t, RegistryHosting)
reg, err := newTestRegistryV2(t)