X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/df5453354edc2e6a3db198884b9c5bd0f86fed7c..b86543493dffefb1ec245f48550cfa9e0119f4d1:/services/crunch-run/logging_test.go diff --git a/services/crunch-run/logging_test.go b/services/crunch-run/logging_test.go index bce324d478..ceb8ca87b0 100644 --- a/services/crunch-run/logging_test.go +++ b/services/crunch-run/logging_test.go @@ -4,6 +4,7 @@ import ( "fmt" "git.curoverse.com/arvados.git/sdk/go/arvadosclient" . "gopkg.in/check.v1" + "testing" "time" ) @@ -15,7 +16,11 @@ type TestTimestamper struct { func (this *TestTimestamper) Timestamp(t time.Time) string { this.count += 1 - return fmt.Sprintf("2015-12-29T15:51:45.%09dZ", this.count) + t, err := time.ParseInLocation(time.RFC3339Nano, fmt.Sprintf("2015-12-29T15:51:45.%09dZ", this.count), t.Location()) + if err != nil { + panic(err) + } + return RFC3339Timestamp(t) } // Gocheck boilerplate @@ -40,19 +45,22 @@ func (s *LoggingTestSuite) TestWriteLogs(c *C) { logtext := "2015-12-29T15:51:45.000000001Z Hello world!\n" + "2015-12-29T15:51:45.000000002Z Goodbye\n" - c.Check(api.Content["log"].(arvadosclient.Dict)["event_type"], Equals, "crunch-run") - c.Check(api.Content["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"], Equals, logtext) + c.Check(api.Content[0]["log"].(arvadosclient.Dict)["event_type"], Equals, "crunch-run") + c.Check(api.Content[0]["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"], Equals, logtext) c.Check(string(kc.Content), Equals, logtext) } func (s *LoggingTestSuite) TestWriteLogsLarge(c *C) { + if testing.Short() { + return + } api := &ArvTestClient{} kc := &KeepTestClient{} cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzzzzzzzzzzzz") cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp cr.CrunchLog.Immediate = nil - for i := 0; i < 2000000; i += 1 { + for i := 0; i < 2000000; i++ { cr.CrunchLog.Printf("Hello %d", i) } cr.CrunchLog.Print("Goodbye") @@ -79,18 +87,21 @@ func (s *LoggingTestSuite) TestWriteMultipleLogs(c *C) { stdout.Print("Doing stuff") cr.CrunchLog.Print("Goodbye") stdout.Print("Blurb") - cr.CrunchLog.Close() - logtext1 := "2015-12-29T15:51:45.000000001Z Hello world!\n" + - "2015-12-29T15:51:45.000000003Z Goodbye\n" - c.Check(api.Content["log"].(arvadosclient.Dict)["event_type"], Equals, "crunch-run") - c.Check(api.Content["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"], Equals, logtext1) - stdout.Close() - logtext2 := "2015-12-29T15:51:45.000000002Z Doing stuff\n" + - "2015-12-29T15:51:45.000000004Z Blurb\n" - c.Check(api.Content["log"].(arvadosclient.Dict)["event_type"], Equals, "stdout") - c.Check(api.Content["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"], Equals, logtext2) + + logText := make(map[string]string) + for _, content := range api.Content { + log := content["log"].(arvadosclient.Dict) + logText[log["event_type"].(string)] += log["properties"].(map[string]string)["text"] + } + + c.Check(logText["crunch-run"], Equals, `2015-12-29T15:51:45.000000001Z Hello world! +2015-12-29T15:51:45.000000003Z Goodbye +`) + c.Check(logText["stdout"], Equals, `2015-12-29T15:51:45.000000002Z Doing stuff +2015-12-29T15:51:45.000000004Z Blurb +`) mt, err := cr.LogCollection.ManifestText() c.Check(err, IsNil)