Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEBUG mode broke tests #430

Merged
merged 1 commit into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ version: "3.7"
services:
semian: &base
container_name: semian
environment:
DEBUG: "1"
build:
dockerfile: .devcontainer/Dockerfile
context: ..
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Avoid prepending the same prefix twice to errors messages. (#423)
This mostly happens with the `redis-rb 5+` gem as it translate `redis-client` errors.
* Fix running tests in DEBUG mode to test missing semaphores resources. (#430)

# v0.16.0

Expand Down
16 changes: 16 additions & 0 deletions ext/semian/sysv_semaphores.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,19 @@ diff_timespec_ms(struct timespec *end, struct timespec *begin)
long begin_ms = (begin->tv_sec * 1e3) + (begin->tv_nsec / 1e6);
return end_ms - begin_ms;
}

#ifdef DEBUG
VALUE
print_sem_vals_without_rescue(VALUE v_sem_id)
{
int sem_id = rb_to_int(v_sem_id);
printf("[pid=%d][semian] semaphore values lock: %d, tickets: %d configured: %d, registered workers: %d\n",
getpid(),
get_sem_val(sem_id, SI_SEM_LOCK),
get_sem_val(sem_id, SI_SEM_TICKETS),
get_sem_val(sem_id, SI_SEM_CONFIGURED_TICKETS),
get_sem_val(sem_id, SI_SEM_REGISTERED_WORKERS)
);
return (VALUE)0;
}
#endif
12 changes: 5 additions & 7 deletions ext/semian/sysv_semaphores.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,14 @@ void *
acquire_semaphore_without_gvl(void *p);

#ifdef DEBUG
VALUE
print_sem_vals_without_rescue(VALUE v_sem_id);

static inline void
print_sem_vals(int sem_id)
{
printf("[pid=%d][semian] semaphore values lock: %d, tickets: %d configured: %d, registered workers: %d\n",
getpid(),
get_sem_val(sem_id, SI_SEM_LOCK),
get_sem_val(sem_id, SI_SEM_TICKETS),
get_sem_val(sem_id, SI_SEM_CONFIGURED_TICKETS),
get_sem_val(sem_id, SI_SEM_REGISTERED_WORKERS)
);
int state;
rb_protect(print_sem_vals_without_rescue, INT2NUM(sem_id), &state);
}
#endif

Expand Down
3 changes: 2 additions & 1 deletion test/resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,10 @@ def test_sem_undo
def test_destroy
resource = create_resource(:testing, tickets: 1)
resource.destroy
assert_raises(Semian::SyscallError) do
exception = assert_raises(Semian::SyscallError) do
resource.acquire {}
end
assert_equal("semop() failed, errno: 22 (Invalid argument)", exception.message)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally speaking it's a good idea to use assert_includes or assert_match when testing error messages, because did_you_mean error_highlight etc might augment the error message.

end

def test_destroy_already_destroyed
Expand Down