17830: Add test for logging request ID.
authorTom Clegg <tom@curii.com>
Wed, 29 Sep 2021 14:17:11 +0000 (10:17 -0400)
committerWard Vandewege <ward@curii.com>
Wed, 6 Oct 2021 12:59:52 +0000 (08:59 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

services/api/test/integration/logging_test.rb [new file with mode: 0644]

diff --git a/services/api/test/integration/logging_test.rb b/services/api/test/integration/logging_test.rb
new file mode 100644 (file)
index 0000000..cbf9681
--- /dev/null
@@ -0,0 +1,28 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
+require 'stringio'
+
+class LoggingTest < ActionDispatch::IntegrationTest
+  fixtures :collections
+
+  test "request_id" do
+    buf = StringIO.new
+    logcopy = ActiveSupport::Logger.new(buf)
+    logcopy.level = :info
+    begin
+      Rails.logger.extend(ActiveSupport::Logger.broadcast(logcopy))
+      get "/arvados/v1/collections/#{collections(:foo_file).uuid}",
+          params: {:format => :json},
+          headers: auth(:active).merge({ 'X-Request-Id' => 'req-aaaaaaaaaaaaaaaaaaaa' })
+      assert_response :success
+      assert_match /^{.*"request_id":"req-aaaaaaaaaaaaaaaaaaaa"/, buf.string
+    ensure
+      # We don't seem to have an "unbroadcast" option, so this is how
+      # we avoid filling buf with unlimited logs from subsequent
+      # tests.
+      logcopy.level = :fatal
+    end
+  end
+end