Skip to content

Commit

Permalink
close #75: fix crash on non-released preemptive resources when capaci…
Browse files Browse the repository at this point in the history
…ty decreases
  • Loading branch information
Enchufa2 committed Sep 30, 2016
1 parent 1f01f83 commit b95d6ff
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Remove warnings for unused arguments in `seize` and `seize_selected` (1c8c3bb).
* Fix crash on arrival reneging in non-triggered batches (8713d95).
* Fix crash on batches triggered before the timer expires (8713d95).
* Fix crash on non-released preemptive resources when capacity decreases (#75).

# Changes in version 3.4.2

Expand Down
2 changes: 2 additions & 0 deletions src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ class PreemptiveRes : public PriorityRes<T> {

bool try_free_server(bool verbose, double time) {
typename T::iterator first = this->server.begin();
if (first == this->server.end())
return false;
first->arrival->deactivate();
if (verbose) this->verbose_print(time, first->arrival->name, "PREEMPT");
if (first->arrival->is_monitored()) {
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-simmer-resource-schedule.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,16 @@ test_that("resource's capacity decreases before post-release tasks", {
expect_equal(arrivals$end_time, c(10, 20, 25))
expect_equal(arrivals$activity_time, c(5, 5, 5))
})

test_that("capacity decrease on a non-released preemptive resource does not crash", {
t <- create_trajectory() %>%
seize("dummy", 1)

sched <- schedule(c(0, 1), c(1, 0), period = Inf)

env <- simmer(verbose = TRUE) %>%
add_resource("dummy", sched, preemptive = TRUE) %>%
add_generator("arrival", t, at(0))

expect_output(run(env))
})

0 comments on commit b95d6ff

Please sign in to comment.