5 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
11 type LoggingTestSuite struct{}
13 type TestTimestamper struct {
17 func (this *TestTimestamper) Timestamp(t time.Time) string {
19 t, err := time.ParseInLocation(time.RFC3339Nano, fmt.Sprintf("2015-12-29T15:51:45.%09dZ", this.count), t.Location())
23 return RFC3339Timestamp(t)
26 // Gocheck boilerplate
27 var _ = Suite(&LoggingTestSuite{})
29 func (s *LoggingTestSuite) TestWriteLogs(c *C) {
30 api := &ArvTestClient{}
31 kc := &KeepTestClient{}
32 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzzzzzzzzzzzz")
33 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
35 cr.CrunchLog.Print("Hello world!")
36 cr.CrunchLog.Print("Goodbye")
39 c.Check(api.Calls, Equals, 1)
41 mt, err := cr.LogCollection.ManifestText()
43 c.Check(mt, Equals, ". 74561df9ae65ee9f35d5661d42454264+83 0:83:crunch-run.txt\n")
45 logtext := "2015-12-29T15:51:45.000000001Z Hello world!\n" +
46 "2015-12-29T15:51:45.000000002Z Goodbye\n"
48 c.Check(api.Content[0]["log"].(arvadosclient.Dict)["event_type"], Equals, "crunch-run")
49 c.Check(api.Content[0]["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"], Equals, logtext)
50 c.Check(string(kc.Content), Equals, logtext)
53 func (s *LoggingTestSuite) TestWriteLogsLarge(c *C) {
57 api := &ArvTestClient{}
58 kc := &KeepTestClient{}
59 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzzzzzzzzzzzz")
60 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
61 cr.CrunchLog.Immediate = nil
63 for i := 0; i < 2000000; i++ {
64 cr.CrunchLog.Printf("Hello %d", i)
66 cr.CrunchLog.Print("Goodbye")
69 c.Check(api.Calls > 1, Equals, true)
70 c.Check(api.Calls < 2000000, Equals, true)
72 mt, err := cr.LogCollection.ManifestText()
74 c.Check(mt, Equals, ". 9c2c05d1fae6aaa8af85113ba725716d+67108864 80b821383a07266c2a66a4566835e26e+21780065 0:88888929:crunch-run.txt\n")
77 func (s *LoggingTestSuite) TestWriteMultipleLogs(c *C) {
78 api := &ArvTestClient{}
79 kc := &KeepTestClient{}
80 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzzzzzzzzzzzz")
81 ts := &TestTimestamper{}
82 cr.CrunchLog.Timestamper = ts.Timestamp
83 stdout := NewThrottledLogger(cr.NewLogWriter("stdout"))
84 stdout.Timestamper = ts.Timestamp
86 cr.CrunchLog.Print("Hello world!")
87 stdout.Print("Doing stuff")
88 cr.CrunchLog.Print("Goodbye")
93 logText := make(map[string]string)
94 for _, content := range api.Content {
95 log := content["log"].(arvadosclient.Dict)
96 logText[log["event_type"].(string)] += log["properties"].(map[string]string)["text"]
99 c.Check(logText["crunch-run"], Equals, `2015-12-29T15:51:45.000000001Z Hello world!
100 2015-12-29T15:51:45.000000003Z Goodbye
102 c.Check(logText["stdout"], Equals, `2015-12-29T15:51:45.000000002Z Doing stuff
103 2015-12-29T15:51:45.000000004Z Blurb
106 mt, err := cr.LogCollection.ManifestText()
108 c.Check(mt, Equals, ""+
109 ". 408672f5b5325f7d20edfbf899faee42+83 0:83:crunch-run.txt\n"+
110 ". c556a293010069fa79a6790a931531d5+80 0:80:stdout.txt\n")