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["log"].(arvadosclient.Dict)["event_type"], Equals, "crunch-run")
44 c.Check(api.Content["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
54 for i := 0; i < 2000000; i += 1 {
55 cr.CrunchLog.Printf("Hello %d", i)
57 cr.CrunchLog.Print("Goodbye")
60 c.Check(api.Calls > 1, Equals, true)
61 c.Check(api.Calls < 2000000, Equals, true)
63 mt, err := cr.LogCollection.ManifestText()
65 c.Check(mt, Equals, ". 9c2c05d1fae6aaa8af85113ba725716d+67108864 80b821383a07266c2a66a4566835e26e+21780065 0:88888929:crunch-run.txt\n")
68 func (s *LoggingTestSuite) TestWriteMultipleLogs(c *C) {
69 api := &ArvTestClient{}
70 kc := &KeepTestClient{}
71 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzzzzzzzzzzzz")
72 ts := &TestTimestamper{}
73 cr.CrunchLog.Timestamper = ts.Timestamp
74 stdout := NewThrottledLogger(cr.NewLogWriter("stdout"))
75 stdout.Timestamper = ts.Timestamp
77 cr.CrunchLog.Print("Hello world!")
78 stdout.Print("Doing stuff")
79 cr.CrunchLog.Print("Goodbye")
83 logtext1 := "2015-12-29T15:51:45.000000001Z Hello world!\n" +
84 "2015-12-29T15:51:45.000000003Z Goodbye\n"
85 c.Check(api.Content["log"].(arvadosclient.Dict)["event_type"], Equals, "crunch-run")
86 c.Check(api.Content["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"], Equals, logtext1)
89 logtext2 := "2015-12-29T15:51:45.000000002Z Doing stuff\n" +
90 "2015-12-29T15:51:45.000000004Z Blurb\n"
91 c.Check(api.Content["log"].(arvadosclient.Dict)["event_type"], Equals, "stdout")
92 c.Check(api.Content["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"], Equals, logtext2)
94 mt, err := cr.LogCollection.ManifestText()
96 c.Check(mt, Equals, ""+
97 ". 408672f5b5325f7d20edfbf899faee42+83 0:83:crunch-run.txt\n"+
98 ". c556a293010069fa79a6790a931531d5+80 0:80:stdout.txt\n")