mirror of
https://github.com/wassname/ray.git
synced 2026-06-27 18:44:07 +08:00
[Java]Fix testSetResource bug (#11064)
Co-authored-by: 灵洵 <fengbin.ffb@antfin.com>
This commit is contained in:
@@ -20,19 +20,23 @@ public class DynamicResourceTest extends BaseTest {
|
||||
// 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);
|
||||
|
||||
Reference in New Issue
Block a user