Skip to content
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
15 changes: 11 additions & 4 deletions tests/unit/test_logs.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "sentry_logs.h"
#include "sentry_sync.h"
#include "sentry_testsupport.h"

#include "sentry_envelope.h"
Expand All @@ -13,7 +14,7 @@
#endif

typedef struct {
uint64_t called_count;
volatile long called_count;
bool has_validation_error;
} transport_validation_data_t;

Expand All @@ -37,7 +38,7 @@ validate_logs_envelope(sentry_envelope_t *envelope, void *data)

// Only validate and count log envelopes, skip others (e.g., session)
if (strcmp(type, "log") == 0) {
validation_data->called_count += 1;
sentry__atomic_fetch_and_add(&validation_data->called_count, 1);
}

sentry_envelope_free(envelope);
Expand Down Expand Up @@ -65,8 +66,14 @@ SENTRY_TEST(basic_logging_functionality)
TEST_CHECK_INT_EQUAL(sentry_log_info("Info message"), 0);
TEST_CHECK_INT_EQUAL(sentry_log_warn("Warning message"), 0);
TEST_CHECK_INT_EQUAL(sentry_log_error("Error message"), 0);
// Sleep to allow first batch to flush (testing batch timing behavior)
sleep_ms(20);
// Sleep up to 5s to allow first batch to flush (testing batch timing
// behavior)
for (int i = 0;
i < 250 && sentry__atomic_fetch(&validation_data.called_count) < 1;
i++) {
sleep_ms(20);
}
TEST_CHECK_INT_EQUAL(validation_data.called_count, 1);
TEST_CHECK_INT_EQUAL(sentry_log_fatal("Fatal message"), 0);
sentry_close();

Expand Down
14 changes: 10 additions & 4 deletions tests/unit/test_metrics.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "sentry_metrics.h"
#include "sentry_sync.h"
#include "sentry_testsupport.h"

#include "sentry_envelope.h"
Expand All @@ -13,7 +14,7 @@
#endif

typedef struct {
uint64_t called_count;
volatile long called_count;
bool has_validation_error;
} transport_validation_data_t;

Expand All @@ -36,7 +37,7 @@ validate_metrics_envelope(sentry_envelope_t *envelope, void *data)

// Only validate and count metric envelopes, skip others (e.g., session)
if (strcmp(type, "trace_metric") == 0) {
validation_data->called_count += 1;
sentry__atomic_fetch_and_add(&validation_data->called_count, 1);
}

sentry_envelope_free(envelope);
Expand Down Expand Up @@ -146,8 +147,13 @@ SENTRY_TEST(metrics_batch)
sentry_metrics_count("test.counter", 1, sentry_value_new_null()),
SENTRY_METRICS_RESULT_SUCCESS);
}
// Sleep to allow first batch to flush
sleep_ms(20);
// Sleep up to 5s to allow first batch to flush
for (int i = 0;
i < 250 && sentry__atomic_fetch(&validation_data.called_count) < 1;
i++) {
sleep_ms(20);
}
TEST_CHECK_INT_EQUAL(validation_data.called_count, 1);
TEST_CHECK_INT_EQUAL(
sentry_metrics_count("test.counter", 1, sentry_value_new_null()),
SENTRY_METRICS_RESULT_SUCCESS);
Expand Down
Loading