Add 'apps/arv-web/' from commit 'f9732ad8460d013c2f28363655d0d1b91894dca5'
[arvados.git] / services / api / test / unit / node_test.rb
index ccc3765dd94060d98bed4b59f5f55b111292e8e4..37e95db0e18cfb555de27a7b127d1d90cf132052 100644 (file)
@@ -1,7 +1,29 @@
 require 'test_helper'
 
 class NodeTest < ActiveSupport::TestCase
-  # test "the truth" do
-  #   assert true
-  # end
+  def ping_node(node_name, ping_data)
+    set_user_from_auth :admin
+    node = nodes(node_name)
+    node.ping({ping_secret: node.info['ping_secret'],
+                ip: node.ip_address}.merge(ping_data))
+    node
+  end
+
+  test "pinging a node can add and update stats" do
+    node = ping_node(:idle, {total_cpu_cores: '12', total_ram_mb: '512'})
+    assert_equal(12, node.properties['total_cpu_cores'])
+    assert_equal(512, node.properties['total_ram_mb'])
+  end
+
+  test "stats disappear if not in a ping" do
+    node = ping_node(:idle, {total_ram_mb: '256'})
+    refute_includes(node.properties, 'total_cpu_cores')
+    assert_equal(256, node.properties['total_ram_mb'])
+  end
+
+  test "worker state is down for node with no slot" do
+    node = nodes(:was_idle_now_down)
+    assert_nil node.slot_number, "fixture is not what I expected"
+    assert_equal 'down', node.crunch_worker_state, "wrong worker state"
+  end
 end