Skip to content

Commit

Permalink
[Java]Fix testSetResource bug (#11064)
Browse files Browse the repository at this point in the history
Co-authored-by: 灵洵 <fengbin.ffb@antfin.com>
  • Loading branch information
ffbin and 灵洵 authored Sep 28, 2020
1 parent 25ac8f9 commit dd97f0c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions java/test/src/main/java/io/ray/test/DynamicResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,23 @@ public void testSetResource() {
// Call a task in advance to warm up the cluster to avoid being too slow to start workers.
TestUtils.warmUpCluster();

String resourceName = "A";
ObjectRef<String> obj = Ray.task(DynamicResourceTest::sayHi)
.setResource("A", 10.0)
.setResource(resourceName, 10.0)
.remote();
WaitResult<String> result = Ray.wait(ImmutableList.of(obj), 1, 1000);
Assert.assertEquals(result.getReady().size(), 0);

Ray.setResource("A", 10.0);
Ray.setResource(resourceName, 10.0);
boolean resourceReady = TestUtils.waitForCondition(() -> {
List<NodeInfo> nodes = Ray.getRuntimeContext().getAllNodeInfo();
if (nodes.size() != 1) {
// NOTE: GCS updates node resources asynchronously.
// If we directly get the value of "A" for comparison without check whether "A" exists or not,
// it maybe lead to NPE.
if (nodes.size() != 1 || !nodes.get(0).resources.containsKey(resourceName)) {
return false;
}
return (0 == Double.compare(10.0, nodes.get(0).resources.get("A")));
return (0 == Double.compare(10.0, nodes.get(0).resources.get(resourceName)));
}, 2000);

Assert.assertTrue(resourceReady);
Expand Down

0 comments on commit dd97f0c

Please sign in to comment.