瀏覽代碼

crystal|lucky update test fix (#6128)

Matthew McGarvey 5 年之前
父節點
當前提交
002c97f38a
共有 1 個文件被更改,包括 8 次插入1 次删除
  1. 8 1
      frameworks/Crystal/lucky/src/actions/updates/index.cr

+ 8 - 1
frameworks/Crystal/lucky/src/actions/updates/index.cr

@@ -4,7 +4,14 @@ class Updates::Index < BaseAction
   get "/updates" do
     results = (1..queries_param).map do
       world = WorldQuery.find(rand(1..ID_MAXIMUM))
-      world = SaveWorld.update!(world, randomnumber: rand(1..ID_MAXIMUM))
+      # Avram does not perform the update operation if no value has changed
+      # so we have to keep generating random numbers until we
+      # get one that is different than the currently set one
+      random_number = rand(1..ID_MAXIMUM)
+      while random_number == world.randomnumber
+        random_number = rand(1..ID_MAXIMUM)
+      end
+      world = SaveWorld.update!(world, randomnumber: random_number)
       WorldSerializer.new(world)
     end