Merge branch '8784-dir-listings'
[arvados.git] / services / crunch-run / logging_test.go
index 91af16dc4970386b4c8f8301387b0b32943e5df7..87593be9bfe01f6e7d3b057157d3e980b752211c 100644 (file)
@@ -1,9 +1,14 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
 package main
 
 import (
        "fmt"
        "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
        . "gopkg.in/check.v1"
+       "strings"
        "testing"
        "time"
 )
@@ -110,7 +115,24 @@ func (s *LoggingTestSuite) TestWriteMultipleLogs(c *C) {
                ". c556a293010069fa79a6790a931531d5+80 0:80:stdout.txt\n")
 }
 
-func (s *LoggingTestSuite) TestWriteLogsWithRateLimit(c *C) {
+func (s *LoggingTestSuite) TestWriteLogsWithRateLimitThrottleBytes(c *C) {
+       testWriteLogsWithRateLimit(c, "crunchLogThrottleBytes", 50, 65536, "Exceeded rate 50 bytes per 60 seconds")
+}
+
+func (s *LoggingTestSuite) TestWriteLogsWithRateLimitThrottleLines(c *C) {
+       testWriteLogsWithRateLimit(c, "crunchLogThrottleLines", 1, 1024, "Exceeded rate 1 lines per 60 seconds")
+}
+
+func (s *LoggingTestSuite) TestWriteLogsWithRateLimitThrottleBytesPerEvent(c *C) {
+       testWriteLogsWithRateLimit(c, "crunchLimitLogBytesPerJob", 50, 67108864, "Exceeded log limit 50 bytes (crunch_limit_log_bytes_per_job)")
+}
+
+func testWriteLogsWithRateLimit(c *C, throttleParam string, throttleValue int, throttleDefault int, expected string) {
+       discoveryMap[throttleParam] = float64(throttleValue)
+       defer func() {
+               discoveryMap[throttleParam] = float64(throttleDefault)
+       }()
+
        api := &ArvTestClient{}
        kc := &KeepTestClient{}
        cr := NewContainerRunner(api, kc, nil, "zzzzz-zzzzzzzzzzzzzzz")
@@ -130,6 +152,7 @@ func (s *LoggingTestSuite) TestWriteLogsWithRateLimit(c *C) {
                "2015-12-29T15:51:45.000000002Z Goodbye\n"
 
        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)
+       stderrLog := api.Content[0]["log"].(arvadosclient.Dict)["properties"].(map[string]string)["text"]
+       c.Check(true, Equals, strings.Contains(stderrLog, expected))
        c.Check(string(kc.Content), Equals, logtext)
 }