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 return fmt.Sprintf("2015-12-29T15:51:45.%09dZ", this.count)
22 // Gocheck boilerplate
23 var _ = Suite(&LoggingTestSuite{})
25 func (s *LoggingTestSuite) TestWriteLogs(c *C) {
26 api := &ArvTestClient{}
27 kc := &KeepTestClient{}
28 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzzzzzzzzzzzz")
29 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
31 cr.CrunchLog.Print("Hello world!")
32 cr.CrunchLog.Print("Goodbye")
35 c.Check(api.Calls, Equals, 1)
37 mt, err := cr.LogCollection.ManifestText()
39 c.Check(mt, Equals, ". 74561df9ae65ee9f35d5661d42454264+83 0:83:crunch-run.txt\n")
41 logtext := "2015-12-29T15:51:45.000000001Z Hello world!\n" +
42 "2015-12-29T15:51:45.000000002Z Goodbye\n"
44 c.Check(api.Content[0]["log"].(arvadosclient.Dict)["event_type"], Equals, "crunch-run")
45 c.Check(api.Content[0]["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"], Equals, logtext)
46 c.Check(string(kc.Content), Equals, logtext)
49 func (s *LoggingTestSuite) TestWriteLogsLarge(c *C) {
53 api := &ArvTestClient{}
54 kc := &KeepTestClient{}
55 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzzzzzzzzzzzz")
56 cr.CrunchLog.Timestamper = (&TestTimestamper{}).Timestamp
57 cr.CrunchLog.Immediate = nil
59 for i := 0; i < 2000000; i++ {
60 cr.CrunchLog.Printf("Hello %d", i)
62 cr.CrunchLog.Print("Goodbye")
65 c.Check(api.Calls > 1, Equals, true)
66 c.Check(api.Calls < 2000000, Equals, true)
68 mt, err := cr.LogCollection.ManifestText()
70 c.Check(mt, Equals, ". 9c2c05d1fae6aaa8af85113ba725716d+67108864 80b821383a07266c2a66a4566835e26e+21780065 0:88888929:crunch-run.txt\n")
73 func (s *LoggingTestSuite) TestWriteMultipleLogs(c *C) {
74 api := &ArvTestClient{}
75 kc := &KeepTestClient{}
76 cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzzzzzzzzzzzz")
77 ts := &TestTimestamper{}
78 cr.CrunchLog.Timestamper = ts.Timestamp
79 stdout := NewThrottledLogger(cr.NewLogWriter("stdout"))
80 stdout.Timestamper = ts.Timestamp
82 cr.CrunchLog.Print("Hello world!")
83 stdout.Print("Doing stuff")
84 cr.CrunchLog.Print("Goodbye")
89 logText := make(map[string]string)
90 for _, content := range api.Content {
91 log := content["log"].(arvadosclient.Dict)
92 logText[log["event_type"].(string)] += log["properties"].(map[string]string)["text"]
95 c.Check(logText["crunch-run"], Equals, `2015-12-29T15:51:45.000000001Z Hello world!
96 2015-12-29T15:51:45.000000003Z Goodbye
98 c.Check(logText["stdout"], Equals, `2015-12-29T15:51:45.000000002Z Doing stuff
99 2015-12-29T15:51:45.000000004Z Blurb
102 mt, err := cr.LogCollection.ManifestText()
104 c.Check(mt, Equals, ""+
105 ". 408672f5b5325f7d20edfbf899faee42+83 0:83:crunch-run.txt\n"+
106 ". c556a293010069fa79a6790a931531d5+80 0:80:stdout.txt\n")