Skip to content

Introduce a waiting process as a test utility - #589

Open
cameron-craig-etas wants to merge 1 commit into
eclipse-score:mainfrom
etas-contrib:feature/waiting-process
Open

Introduce a waiting process as a test utility#589
cameron-craig-etas wants to merge 1 commit into
eclipse-score:mainfrom
etas-contrib:feature/waiting-process

Conversation

@cameron-craig-etas

@cameron-craig-etas cameron-craig-etas commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

#588

This PR introduces a "waiting" process that goes hand-in-hand with the "counting" process being introduced in /pull/587. The process takes some required arguments to configure the semaphore name, and the expected count. Optionally, this process can be used to start from zero, which deletes the named semaphore before starting.

I've tested this locally:

  • Tested that the semaphore is created and posted to correctly
$ bazel build //tests/utils/test_helper:waiting_process
$ bazel-bin/tests/utils/test_helper/waiting_process -p /namedsem
$ stat -c '%a %n' /dev/shm/sem.namedsem
644 /dev/shm/sem.namedsem
$ ./bin/python3 -c "import posix_ipc; sem = posix_ipc.Semaphore('/namedsem'); print('Value:', sem.value)"
Value: 1
$ bazel-bin/tests/utils/test_helper/counting_process  -p /namedsem
Value: 2
  • Tested that errors are reported when arguments are missing
    $ bazel-bin/tests/utils/test_helper/waiting_process
    Invalid arguments! Must provide at least one option.
    
    $ bazel-bin/tests/utils/test_helper/waiting_process -n /namedsem
    Invalid arguments! An expected count must be provided.
    
    $ bazel-bin/tests/utils/test_helper/waiting_process -c
    $ bazel-bin/tests/utils/test_helper/waiting_process: option requires an argument -- 'c'
    Invalid or missing argument.
    
    $ bazel-bin/tests/utils/test_helper/waiting_process -c 10
    Invalid arguments! Must provide at least one option.
    
    $ bazel-bin/tests/utils/test_helper/waiting_process -p
    $ bazel-bin/tests/utils/test_helper/waiting_process: invalid option -- 'p'
    Invalid or missing argument.
    
    $ bazel-bin/tests/utils/test_helper/waiting_process -z
    Invalid arguments! A semaphore name must be passed if starting from zero.
    
  • Tested that the process waits until the expected count is reached
    $ bazel-bin/tests/utils/test_helper/waiting_process -n /sem -c 10
    (post 10 times using counting_procees)...
    echo $?
    0
    
  • Tested that the semaphore is deleted if passing -z
    $ bazel-bin/tests/utils/test_helper/counting_process -p /sem # Create sem
    $ file /dev/shm/sem.sem # Check exists
    /dev/shm/sem.sem: data
    $ bazel-bin/tests/utils/test_helper/waiting_process -z -n /sem # Delete
    $ file /dev/shm/sem.sem # Check deleted
    /dev/shm/sem.sem: cannot open `/dev/shm/sem.sem' (No such file or directory)
    
  • Tested that the help option works
    $ bazel-bin/tests/utils/test_helper/waiting_process -h
    Usage: ./wait_for_semaphore --semaphore-name <semaphore_name> --expected-count <expected_count> [--timeout-seconds <timeout in seconds>] [--start-from-zero]
    $ bazel-bin/tests/utils/test_helper/waiting_process --help
    Usage: ./wait_for_semaphore --semaphore-name <semaphore_name> --expected-count <expected_count> [--timeout-seconds <timeout in seconds>] [--start-from-zero]
    
  • Test that interger parsing can fail
    $ bazel-bin/tests/utils/test_helper/waiting_process -c k
    Could not parse expected-count as integer: k
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant