Skip to content

Commit

Permalink
Implements sooner resource validity checking
Browse files Browse the repository at this point in the history
  • Loading branch information
spirali committed May 3, 2024
1 parent 9c4d27b commit 9dc9206
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
7 changes: 4 additions & 3 deletions crates/hyperqueue/src/client/commands/submit/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,13 @@ impl JobSubmitOpts {
},
)
}

Ok(ResourceRequest {
let request = ResourceRequest {
n_nodes: self.conf.nodes,
min_time: self.conf.time_request,
resources,
})
};
request.validate()?;
Ok(request)
}
}

Expand Down
18 changes: 18 additions & 0 deletions crates/tako/src/gateway.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use serde::{Deserialize, Serialize, Serializer};

use crate::internal::common::error::DsError;
use crate::internal::messages::common::TaskFailInfo;
use crate::internal::messages::worker::WorkerOverview;
use crate::internal::worker::configuration::WorkerConfiguration;
Expand Down Expand Up @@ -44,6 +45,23 @@ impl Default for ResourceRequest {
}
}

impl ResourceRequest {
pub fn validate(&self) -> crate::Result<()> {
for (i, entry) in self.resources.iter().enumerate() {
entry.policy.validate()?;
for entry2 in &self.resources[i + 1..] {
if entry.resource == entry2.resource {
return Err(DsError::GenericError(format!(
"Resource '{}' defined more than once",
entry.resource
)));
}
}
}
Ok(())
}
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone)]
pub struct ResourceRequestVariants {
pub variants: SmallVec<[ResourceRequest; 1]>,
Expand Down
13 changes: 13 additions & 0 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,3 +456,16 @@ def test_manual_cpu_resource_sum(hq_env: HqEnv):
args=["worker", "start", "--resource", "cpus=sum(5)"],
expect_fail="Resource kind `sum` cannot be used with CPUs",
)


def test_resources_invalid_definitions(hq_env: HqEnv):
hq_env.start_server()
hq_env.command(
args=["submit", "--resource", "foo=10", "--resource", "foo=1", "--", "sleep", "1"],
expect_fail="Resource 'foo' defined more than once",
)

hq_env.command(
args=["submit", "--resource", "foo=0", "--", "sleep", "1"],
expect_fail="Zero resources cannot be requested",
)

0 comments on commit 9dc9206

Please sign in to comment.