10484: Track non-s3 errors by Go type.
[arvados.git] / services / crunch-run / logging_test.go
index bce324d478571aefe0dddf0a0647199a3f0fc1e4..ceb8ca87b00ba25a0a9dc1ac2f2f6ca591cdd0b8 100644 (file)
@@ -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)