示例#1
0
def do_simulator_run(simulator, profiles, t, at, profile_ind, override):
    profile = profiles[profile_ind]
    line = profile.line
    cost = profile.cost
    length = profile.n_steps
    total_inputs = sum(_.quantity
                       for _ in profile.process.inputs) if at >= t else 0
    total_outputs = (sum(
        _.quantity
        for _ in profile.process.outputs) if at >= t + profile.n_steps else 0)

    job = Job(
        profile=profile_ind,
        time=t,
        line=line,
        action="run",
        contract=None,
        override=False,
    )
    simulator.schedule(job=job, override=override)
    assert simulator.wallet_at(at) == (initial_wallet
                                       if at < t else initial_wallet - cost)
    assert (simulator.total_storage_at(at) == sum(initial_storage.values()) -
            total_inputs + total_outputs)
    assert (simulator.line_schedules_at(at)[_] == NO_PRODUCTION
            for _ in range(n_lines) if _ != line)
    if at < t or at >= t + length:
        assert simulator.line_schedules_at(at)[line] == NO_PRODUCTION
示例#2
0
def test_schedule_and_job(factory_with_storage):
    profile_ind = 0
    factory = factory_with_storage
    t = 10
    line = factory.profiles[profile_ind].line
    job = Job(
        profile=profile_ind,
        time=t,
        line=line,
        action="run",
        contract=None,
        override=True,
    )
    factory.schedule(job=job)
    assert len(factory._jobs) == 1
    assert factory._jobs[(t, factory.profiles[profile_ind].line)] == job
    assert factory._wallet == initial_wallet
    assert len(factory._storage) == len(initial_storage)
    assert factory._storage == initial_storage

    profile = factory.profiles[profile_ind]

    # nothing happens before job time
    for _ in range(t):
        infos = factory.step()
        assert all(info.is_empty for info in infos)
        assert all(command.action == "none" for command in factory._commands)

    # the command is executed in job time
    for _ in range(profile.n_steps):
        infos = factory.step()
        assert not any(info.failed for info in infos)
        assert all(command.action == "none"
                   for i, command in enumerate(factory._commands) if i != line)
        if _ == 0:
            assert isinstance(infos[line].started, RunningCommandInfo)
            assert infos[line].started.beg == factory._next_step - 1
            assert infos[
                line].started.end == profile.n_steps + factory._next_step - 1
        if _ == profile.n_steps - 1:
            assert isinstance(infos[line].finished, RunningCommandInfo)
        if 0 < _ < profile.n_steps - 1:
            assert isinstance(infos[line].continuing, RunningCommandInfo)
            assert not infos[line].finished and not infos[line].started

    # nothing happens after job time
    for _ in range(t):
        infos = factory.step()
        assert all(info.no_production for info in infos)
        assert all(command.action == "none" for command in factory._commands)
 def run_profile(self, profile_index, t):
     job = Job(
         profile=profile_index,
         time=t,
         line=self.profiles[profile_index].line,
         action="run",
         contract=None,
         override=False,
     )
     end = t + self.profiles[profile_index].n_steps
     if end > n_steps - 1:
         return
     self.factory.schedule(job=job, override=False)
     self.slow_simulator.schedule(job=job, override=False)
     self.fast_simulator.schedule(job=job, override=False)
示例#4
0
def test_schedule_and_job_with_failures(empty_factory, wallet):
    profile_ind = 0
    factory = empty_factory
    factory._wallet = wallet
    t = 10
    line = factory.profiles[profile_ind].line
    job = Job(
        profile=profile_ind,
        time=t,
        line=line,
        action="run",
        contract=None,
        override=True,
    )
    factory.schedule(job=job)
    assert len(factory._jobs) == 1
    assert factory._jobs[(t, factory.profiles[profile_ind].line)] == job
    assert factory._wallet == wallet
    assert len(factory._storage) == 0
    profile = factory.profiles[profile_ind]

    # nothing happens before job time
    for _ in range(t):
        infos = factory.step()
        assert all(info.is_empty for info in infos)
        assert all(command.action == "none" for command in factory._commands)

    # the command is executed in job time
    infos = factory.step()
    assert not any(info.failed for i, info in enumerate(infos) if i != line)
    assert infos[line].failed
    assert len(infos[line].failure.missing_inputs) > 0
    if wallet < profile.cost:
        assert infos[line].failure.missing_money == profile.cost - wallet

    # nothing happens after job time
    for _ in range(2 * t):
        infos = factory.step()
        assert all(info.no_production for info in infos)
        assert all(command.action == "none" for command in factory._commands)