2857: fix flaky time-sensitive tests
[arvados.git] / services / api / test / functional / arvados / v1 / collections_controller_test.rb
index afda91cc026d98e0d1f7d4f704b6028c70d009ab..ba6929be6497dfc3e62dd9245143d3b5a602e9e5 100644 (file)
@@ -2,6 +2,25 @@ require 'test_helper'
 
 class Arvados::V1::CollectionsControllerTest < ActionController::TestCase
 
+  # StoppedClock.now always returns the same timestamp.
+  # Set the Blob permission signing clock to ensure that
+  # all permission hints use consistent timestamps for testing.
+
+  class StoppedClock
+    @@cached_timestamp = Time.now
+    def self.now
+      return @@cached_timestamp
+    end
+  end
+
+  def setup
+    Blob.set_clock(StoppedClock)
+  end
+
+  def teardown
+    Blob.set_clock(Time)
+  end
+
   test "should get index" do
     authorize_with :active
     get :index
@@ -177,6 +196,20 @@ EOS
     assert_response 422
   end
 
+  test "collection UUID is normalized when created" do
+    authorize_with :active
+    post :create, {
+      collection: {
+        manifest_text: ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n",
+        uuid: "d30fe8ae534397864cb96c544f4cf102+47+Khint+Xhint+Zhint"
+      }
+    }
+    assert_response :success
+    assert_not_nil assigns(:object)
+    resp = JSON.parse(@response.body)
+    assert_equal "d30fe8ae534397864cb96c544f4cf102+47", resp['uuid']
+  end
+
   test "get full provenance for baz file" do
     authorize_with :active
     get :provenance, id: 'ea10d51bcf88862dbcc36eb292017dfd+45'