Skip to content

bug: Authorizer::run() behaves the same for Authorizer::authorize() and Authorizer::authorize_with_limits() when it should not #311

@georglauterbach

Description

@georglauterbach

When not using .set_limits() on an AuthorizerBuilder, the default limits are used. When you set limits with .set_limits(), they are properly set on self (obviously).

pub fn set_limits(mut self, limits: AuthorizerLimits) -> Self {
self.limits = limits;
self
}

This works well with Authorizer::authorize because all limits are properly set beforehand:

pub fn authorize(&mut self) -> Result<usize, error::Token> {
let execution_time = self.run()?;
let mut limits = self.limits.clone();
limits.max_iterations -= self.world.iterations;
if execution_time >= limits.max_time {
return Err(error::Token::RunLimit(error::RunLimit::Timeout));
}
limits.max_time -= execution_time;
self.authorize_with_limits(limits)
}

And the call to self.run() uses the limits from self properly.


Now, when I use Authorizer::authorize_with_limits, the call to self.run() does not propagate these limits as run does not take any limits:

pub fn run(&mut self) -> Result<Duration, error::Token> {
match self.execution_time {
Some(execution_time) => Ok(execution_time),
None => {
let start = Instant::now();
self.world
.run_with_limits(&self.symbols, self.limits.clone())?;
let execution_time = start.elapsed();
self.execution_time = Some(execution_time);
Ok(execution_time)
}
}
}

Hence, the limits from self are used - which are not the limits we explicitly provided when calling authorize_with_limits():

.run_with_limits(&self.symbols, self.limits.clone())?;


This left me with weird test failures because authorize_with_limits() does not propagate the limits properly to run().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions