Skip to content

Commit

Permalink
#147 retry after cancellations up to 3 times (#149)
Browse files Browse the repository at this point in the history
* #147 retry cancellations

* #147 retry cancellations

* #147 retry cancellations

* #147 retry cancellations
  • Loading branch information
alex-courtis authored Jan 16, 2024
1 parent 921aa79 commit 648f1c4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
4 changes: 4 additions & 0 deletions inc/displ.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <stdint.h>

#define MAX_SEQUENTIAL_CANCELLATIONS 3

enum ConfigState {
IDLE = 0,
SUCCEEDED,
Expand All @@ -24,6 +26,8 @@ struct Displ {
uint32_t output_manager_version;

enum ConfigState config_state;

uint32_t sequential_cancellations;
};

void displ_init(void);
Expand Down
13 changes: 11 additions & 2 deletions src/layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,15 @@ void handle_failure(void) {
}
}

void handle_cancelled(void) {
if (displ->sequential_cancellations >= MAX_SEQUENTIAL_CANCELLATIONS) {
log_error("\nChanges cancelled %d times, exiting", MAX_SEQUENTIAL_CANCELLATIONS);
wd_exit_message(EXIT_FAILURE);
} else {
log_warn("\nChanges cancelled, retrying");
}
}

void layout(void) {

print_heads(INFO, ARRIVED, heads_arrived);
Expand All @@ -402,9 +411,9 @@ void layout(void) {
break;

case CANCELLED:
log_warn("\nChanges cancelled, retrying");
handle_cancelled();
displ->config_state = IDLE;
return;
break;

case IDLE:
default:
Expand Down
8 changes: 7 additions & 1 deletion src/listener_output_configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ void cleanup(struct Displ *displ,

zwlr_output_configuration_v1_destroy(zwlr_output_configuration_v1);

if (config_state == CANCELLED) {
displ->sequential_cancellations++;
} else {
displ->sequential_cancellations = 0;
}

displ->config_state = config_state;
}

static void succeeded(void *data,
struct zwlr_output_configuration_v1 *zwlr_output_configuration_v1) {
cleanup(data, zwlr_output_configuration_v1, SUCCEEDED);
cleanup(data, zwlr_output_configuration_v1, CANCELLED);
}

static void failed(void *data,
Expand Down
27 changes: 27 additions & 0 deletions tst/tst-layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <wayland-util.h>

#include "cfg.h"
#include "displ.h"
#include "global.h"
#include "head.h"
#include "info.h"
Expand All @@ -26,6 +27,7 @@ void desire_transform(struct Head *head);
void desire_adaptive_sync(struct Head *head);
void handle_success(void);
void handle_failure(void);
void handle_cancelled(void);

bool __wrap_lid_is_closed(char *name) {
check_expected(name);
Expand Down Expand Up @@ -58,6 +60,8 @@ int after_all(void **state) {
}

int before_each(void **state) {
displ = calloc(1, sizeof(struct Displ));

cfg = cfg_default();

struct State *s = calloc(1, sizeof(struct State));
Expand All @@ -82,6 +86,8 @@ int after_each(void **state) {
head_changing_mode = NULL;
head_changing_adaptive_sync = NULL;

free(displ);

cfg_destroy();

struct State *s = *state;
Expand Down Expand Up @@ -693,6 +699,24 @@ void handle_failure__unspecified(void **state) {
assert_log(ERROR, "\nChanges failed\n");
}

void handle_cancelled__under(void **state) {
displ->sequential_cancellations = 1;

handle_cancelled();

assert_log(WARNING, "\nChanges cancelled, retrying\n");
}

void handle_cancelled__over(void **state) {
displ->sequential_cancellations = MAX_SEQUENTIAL_CANCELLATIONS;

expect_value(__wrap_wd_exit_message, __status, EXIT_FAILURE);

handle_cancelled();

assert_log(ERROR, "\nChanges cancelled 3 times, exiting\n");
}

int main(void) {
const struct CMUnitTest tests[] = {
TEST(order_heads__exact_partial_regex),
Expand Down Expand Up @@ -738,6 +762,9 @@ int main(void) {
TEST(handle_failure__mode),
TEST(handle_failure__adaptive_sync),
TEST(handle_failure__unspecified),

TEST(handle_cancelled__under),
TEST(handle_cancelled__over),
};

return RUN(tests);
Expand Down

0 comments on commit 648f1c4

Please sign in to comment.