| | | 1 | | #include <stdio.h> |
| | | 2 | | #include <assert.h> |
| | | 3 | | #include <string.h> |
| | | 4 | | #include "db_connection.h" |
| | | 5 | | |
| | 1 | 6 | | void test_pool_exhaustion_fail_fast() { |
| | | 7 | | DatabaseConfig cfg; |
| | 1 | 8 | | memset(&cfg, 0, sizeof(DatabaseConfig)); |
| | 1 | 9 | | cfg.pool_min = 1; |
| | 1 | 10 | | cfg.pool_max = 1; |
| | | 11 | | // Initialize pool. Connections will likely fail in local test environment. |
| | 1 | 12 | | db_pool_init(&cfg, FAIL_FAST, 0); |
| | | 13 | | // Attempting to acquire when all (failed) connections are NULL |
| | | 14 | | // should trigger lazy creation, which also fails, and then FAIL_FAST. |
| | 1 | 15 | | DBConnection *c = db_pool_acquire(); |
| | 1 | 16 | | assert(c == NULL); |
| | 1 | 17 | | PoolMetrics m = db_pool_get_metrics(); |
| | 1 | 18 | | assert(m.acquire_cnt == 0); // No successful acquires |
| | 1 | 19 | | db_pool_destroy(); |
| | 1 | 20 | | printf("Pool Exhaustion Fail Fast Test Passed\n"); |
| | 1 | 21 | | } |
| | | 22 | | |
| | 1 | 23 | | void run_db_pool_basic_tests() { |
| | 1 | 24 | | printf("Running DB Pool Basic Tests...\n"); |
| | 1 | 25 | | test_pool_exhaustion_fail_fast(); |
| | 1 | 26 | | printf("DB Pool Basic Tests Passed!\n"); |
| | 1 | 27 | | } |
| | | 28 | | |
| | 1 | 29 | | int main() { |
| | 1 | 30 | | run_db_pool_basic_tests(); |
| | 1 | 31 | | return 0; |
| | | 32 | | } |