5 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
10 type LoggingTestSuite struct{}
12 type TestTimestamper struct {
16 func (this *TestTimestamper) Timestamp(t time.Time) string {
18 return fmt.Sprintf("2015-12-29T15:51:45.%09dZ", this.count)
21 // Gocheck boilerplate
22 var _ = Suite(&LoggingTestSuite{})
24 func (s *LoggingTestSuite) TestWriteLogs(c *C) {
25 api := &ArvTestClient{}
26 kc := &KeepTestClient{}
27 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzzzzzzzzzzzz")
28 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
30 cr.CrunchLog.Print("Hello world!")
31 cr.CrunchLog.Print("Goodbye")
34 c.Check(api.Calls, Equals, 1)
36 mt, err := cr.LogCollection.ManifestText()
38 c.Check(mt, Equals, ". 74561df9ae65ee9f35d5661d42454264+83 0:83:crunch-run.txt\n")
40 logtext := "2015-12-29T15:51:45.000000001Z Hello world!\n" +
41 "2015-12-29T15:51:45.000000002Z Goodbye\n"
43 c.Check(api.Content[0]["log"].(arvadosclient.Dict)["event_type"], Equals, "crunch-run")
44 c.Check(api.Content[0]["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"], Equals, logtext)
45 c.Check(string(kc.Content), Equals, logtext)
48 func (s *LoggingTestSuite) TestWriteLogsLarge(c *C) {
49 api := &ArvTestClient{}
50 kc := &KeepTestClient{}
51 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzzzzzzzzzzzz")
52 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
53 cr.CrunchLog.Immediate = nil
55 for i := 0; i < 2000000; i += 1 {
56 cr.CrunchLog.Printf("Hello %d", i)
58 cr.CrunchLog.Print("Goodbye")
61 c.Check(api.Calls > 1, Equals, true)
62 c.Check(api.Calls < 2000000, Equals, true)
64 mt, err := cr.LogCollection.ManifestText()
66 c.Check(mt, Equals, ". 9c2c05d1fae6aaa8af85113ba725716d+67108864 80b821383a07266c2a66a4566835e26e+21780065 0:88888929:crunch-run.txt\n")
69 func (s *LoggingTestSuite) TestWriteMultipleLogs(c *C) {
70 api := &ArvTestClient{}
71 kc := &KeepTestClient{}
72 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzzzzzzzzzzzz")
73 ts := &TestTimestamper{}
74 cr.CrunchLog.Timestamper = ts.Timestamp
75 stdout := NewThrottledLogger(cr.NewLogWriter("stdout"))
76 stdout.Timestamper = ts.Timestamp
78 cr.CrunchLog.Print("Hello world!")
79 stdout.Print("Doing stuff")
80 cr.CrunchLog.Print("Goodbye")
84 logtext1 := "2015-12-29T15:51:45.000000001Z Hello world!\n" +
85 "2015-12-29T15:51:45.000000003Z Goodbye\n"
86 c.Check(api.Content[0]["log"].(arvadosclient.Dict)["event_type"], Equals, "crunch-run")
87 c.Check(api.Content[0]["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"], Equals, logtext1)
90 logtext2 := "2015-12-29T15:51:45.000000002Z Doing stuff\n" +
91 "2015-12-29T15:51:45.000000004Z Blurb\n"
92 c.Check(api.Content[1]["log"].(arvadosclient.Dict)["event_type"], Equals, "stdout")
93 c.Check(api.Content[1]["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"], Equals, logtext2)
95 mt, err := cr.LogCollection.ManifestText()
97 c.Check(mt, Equals, ""+
98 ". 408672f5b5325f7d20edfbf899faee42+83 0:83:crunch-run.txt\n"+
99 ". c556a293010069fa79a6790a931531d5+80 0:80:stdout.txt\n")