|
1 | 1 | #include "sentry_core.h" |
2 | 2 | #include "sentry_database.h" |
| 3 | +#include "sentry_options.h" |
3 | 4 | #include "sentry_string.h" |
| 5 | +#include "sentry_sync.h" |
4 | 6 | #include "sentry_testsupport.h" |
| 7 | +#include "sentry_transport.h" |
5 | 8 |
|
6 | 9 | static void |
7 | 10 | send_envelope_test_basic(sentry_envelope_t *envelope, void *data) |
@@ -304,3 +307,41 @@ SENTRY_TEST(capture_minidump_invalid_path) |
304 | 307 |
|
305 | 308 | sentry_close(); |
306 | 309 | } |
| 310 | + |
| 311 | +SENTRY_TEST(basic_transport_thread_name) |
| 312 | +{ |
| 313 | + const char *expected_thread_name = "sentry::worker_thread"; |
| 314 | + |
| 315 | + SENTRY_TEST_OPTIONS_NEW(options); |
| 316 | + sentry_options_set_dsn( options, "https://[email protected]/42"); |
| 317 | + sentry_options_set_transport_thread_name(options, expected_thread_name); |
| 318 | + |
| 319 | + // Initialize sentry which should start the transport and set the thread |
| 320 | + // name |
| 321 | + TEST_CHECK_INT_EQUAL(sentry_init(options), 0); |
| 322 | + |
| 323 | + // Access the transport through runtime options to check if thread name was |
| 324 | + // set |
| 325 | + SENTRY_WITH_OPTIONS (runtime_options) { |
| 326 | + TEST_ASSERT(!!runtime_options->transport); |
| 327 | + |
| 328 | + // Get the bgworker from the transport (for HTTP transports) |
| 329 | + sentry_bgworker_t *bgworker |
| 330 | + = (sentry_bgworker_t *)sentry__transport_get_bgworker( |
| 331 | + runtime_options->transport); |
| 332 | + TEST_ASSERT(!!bgworker); |
| 333 | + |
| 334 | + // Check if the thread name was properly set on the bgworker |
| 335 | + const char *actual_thread_name |
| 336 | + = sentry__bgworker_get_thread_name(bgworker); |
| 337 | + |
| 338 | + if (actual_thread_name) { |
| 339 | + TEST_CHECK_STRING_EQUAL(actual_thread_name, expected_thread_name); |
| 340 | + } else { |
| 341 | + TEST_CHECK(false); // Fail if thread_name is NULL |
| 342 | + TEST_MSG("Transport thread name was not set "); |
| 343 | + } |
| 344 | + } |
| 345 | + |
| 346 | + sentry_close(); |
| 347 | +} |
0 commit comments