diff --git a/src/main.c b/src/main.c index 321455a..591ac45 100644 --- a/src/main.c +++ b/src/main.c @@ -51,9 +51,9 @@ int main(int argc, char *argv[]) { while (1) { looper_process_commands(client); { - struct timespec ts = {.tv_sec = 0, .tv_nsec = 50000000}; + struct timespec ts = {.tv_sec = 0, .tv_nsec = 1000000}; nanosleep(&ts, NULL); - } /* check commands every 50 ms */ + } /* check commands every 1 ms */ } jack_client_close(client); diff --git a/tests/integration.c b/tests/integration.c index c7a2e1f..def7767 100644 --- a/tests/integration.c +++ b/tests/integration.c @@ -396,21 +396,24 @@ static int test_multiple_channels(void) { fprintf(stderr, " FAIL: send note 60 failed\n"); return 1; } - /* wait long enough for the looper's main loop to process the add command - (it sleeps for 1 second between checks, so 1.5 s is safe) */ - safe_usleep(1500000); - + /* Poll until the port appears (up to 3 seconds) */ int found = 0; - const char **ports = jack_get_ports(client, NULL, JACK_DEFAULT_AUDIO_TYPE, 0); - if (ports) { - for (int i = 0; ports[i]; i++) { - if (strstr(ports[i], "looper:channel1_input")) { - found = 1; - break; + for (int retries = 0; retries < 30; retries++) { + safe_usleep(100000); + const char **ports = jack_get_ports(client, NULL, JACK_DEFAULT_AUDIO_TYPE, 0); + if (ports) { + for (int i = 0; ports[i]; i++) { + if (strstr(ports[i], "looper:channel1_input")) { + found = 1; + jack_free(ports); + goto port_found; + } } + jack_free(ports); } - jack_free(ports); } +port_found: + ; jack_client_close(client); kill(pid, SIGTERM); waitpid(pid, NULL, 0); @@ -811,18 +814,22 @@ static int test_remove_channel(void) { fprintf(stderr, " FAIL: send note 61 failed\n"); return 1; } - safe_usleep(1500000); - /* verify channel1_input has disappeared */ - ports = jack_get_ports(client, NULL, JACK_DEFAULT_AUDIO_TYPE, 0); - int still_found = 0; - if (ports) { - for (int i = 0; ports[i]; i++) { - if (strstr(ports[i], "looper:channel1_input")) { - still_found = 1; - break; + /* Poll until the port disappears (up to 3 seconds) */ + int still_found = 1; + for (int retries = 0; retries < 30; retries++) { + safe_usleep(100000); + ports = jack_get_ports(client, NULL, JACK_DEFAULT_AUDIO_TYPE, 0); + still_found = 0; + if (ports) { + for (int i = 0; ports[i]; i++) { + if (strstr(ports[i], "looper:channel1_input")) { + still_found = 1; + break; + } } + jack_free(ports); } - jack_free(ports); + if (!still_found) break; } jack_client_close(client); kill(pid, SIGTERM);