|
| 1 | +@rust @rust-3 @min-pool-size |
| 2 | +Feature: min_pool_size enforcement |
| 3 | + Test that min_pool_size setting is enforced at runtime. |
| 4 | + After each retain cycle, pg_doorman should replenish pools below min_pool_size. |
| 5 | + |
| 6 | + Background: |
| 7 | + Given PostgreSQL started with pg_hba.conf: |
| 8 | + """ |
| 9 | + local all all trust |
| 10 | + host all all 127.0.0.1/32 trust |
| 11 | + """ |
| 12 | + And fixtures from "tests/fixture.sql" applied |
| 13 | + |
| 14 | + @replenish-after-startup |
| 15 | + Scenario: Pool replenishes to min_pool_size after startup |
| 16 | + Given pg_doorman started with config: |
| 17 | + """ |
| 18 | + [general] |
| 19 | + host = "127.0.0.1" |
| 20 | + port = ${DOORMAN_PORT} |
| 21 | + admin_username = "admin" |
| 22 | + admin_password = "admin" |
| 23 | + pg_hba.content = "host all all 127.0.0.1/32 trust" |
| 24 | + retain_connections_time = 500 |
| 25 | + server_lifetime = 60000 |
| 26 | +
|
| 27 | + [pools.example_db] |
| 28 | + server_host = "127.0.0.1" |
| 29 | + server_port = ${PG_PORT} |
| 30 | +
|
| 31 | + [[pools.example_db.users]] |
| 32 | + username = "example_user_1" |
| 33 | + password = "" |
| 34 | + pool_size = 5 |
| 35 | + min_pool_size = 3 |
| 36 | + """ |
| 37 | + # Wait for at least 2 retain cycles so replenish can create connections |
| 38 | + When we sleep for 1500 milliseconds |
| 39 | + # Check server connections via admin console |
| 40 | + When we create admin session "admin1" to pg_doorman as "admin" with password "admin" |
| 41 | + And we execute "SHOW SERVERS" on admin session "admin1" and store row count |
| 42 | + Then admin session "admin1" row count should be greater than or equal to 3 |
| 43 | + |
| 44 | + @prewarm-at-startup |
| 45 | + Scenario: Pool is prewarmed at startup before retain cycle |
| 46 | + Given pg_doorman started with config: |
| 47 | + """ |
| 48 | + [general] |
| 49 | + host = "127.0.0.1" |
| 50 | + port = ${DOORMAN_PORT} |
| 51 | + admin_username = "admin" |
| 52 | + admin_password = "admin" |
| 53 | + pg_hba.content = "host all all 127.0.0.1/32 trust" |
| 54 | + retain_connections_time = 60000 |
| 55 | + server_lifetime = 60000 |
| 56 | +
|
| 57 | + [pools.example_db] |
| 58 | + server_host = "127.0.0.1" |
| 59 | + server_port = ${PG_PORT} |
| 60 | +
|
| 61 | + [[pools.example_db.users]] |
| 62 | + username = "example_user_1" |
| 63 | + password = "" |
| 64 | + pool_size = 5 |
| 65 | + min_pool_size = 2 |
| 66 | + """ |
| 67 | + # Wait for prewarm to complete, but retain cycle (60s) has NOT fired yet |
| 68 | + When we sleep for 1000 milliseconds |
| 69 | + When we create admin session "admin1" to pg_doorman as "admin" with password "admin" |
| 70 | + And we execute "SHOW SERVERS" on admin session "admin1" and store row count |
| 71 | + Then admin session "admin1" row count should be greater than or equal to 2 |
| 72 | + |
| 73 | + @maintain-after-expiry |
| 74 | + Scenario: Pool maintains min_pool_size after connections expire |
| 75 | + Given pg_doorman started with config: |
| 76 | + """ |
| 77 | + [general] |
| 78 | + host = "127.0.0.1" |
| 79 | + port = ${DOORMAN_PORT} |
| 80 | + admin_username = "admin" |
| 81 | + admin_password = "admin" |
| 82 | + pg_hba.content = "host all all 127.0.0.1/32 trust" |
| 83 | + retain_connections_time = 500 |
| 84 | + server_lifetime = 1000 |
| 85 | + server_idle_check_timeout = 0 |
| 86 | +
|
| 87 | + [pools.example_db] |
| 88 | + server_host = "127.0.0.1" |
| 89 | + server_port = ${PG_PORT} |
| 90 | +
|
| 91 | + [[pools.example_db.users]] |
| 92 | + username = "example_user_1" |
| 93 | + password = "" |
| 94 | + pool_size = 5 |
| 95 | + min_pool_size = 2 |
| 96 | + """ |
| 97 | + # Create a session and make a query to establish at least 1 backend connection |
| 98 | + When we create session "one" to pg_doorman as "example_user_1" with password "" and database "example_db" |
| 99 | + And we send Parse "" with query "SELECT pg_backend_pid()" to session "one" |
| 100 | + And we send Bind "" to "" with params "" to session "one" |
| 101 | + And we send Execute "" to session "one" |
| 102 | + And we send Sync to session "one" |
| 103 | + Then we remember backend_pid from session "one" as "first_pid" |
| 104 | + # Wait for replenish to bring pool up to min_pool_size |
| 105 | + When we sleep for 2000 milliseconds |
| 106 | + When we create admin session "admin1" to pg_doorman as "admin" with password "admin" |
| 107 | + And we execute "SHOW SERVERS" on admin session "admin1" and store row count |
| 108 | + Then admin session "admin1" row count should be greater than or equal to 2 |
| 109 | + # Wait for server_lifetime (1s ±20% jitter) to expire and retain to close + replenish |
| 110 | + When we sleep for 3000 milliseconds |
| 111 | + And we execute "SHOW SERVERS" on admin session "admin1" and store row count |
| 112 | + Then admin session "admin1" row count should be greater than or equal to 2 |
| 113 | + # Verify the backend was replaced (new PID after lifetime expiry) |
| 114 | + When we send Parse "" with query "SELECT pg_backend_pid()" to session "one" |
| 115 | + And we send Bind "" to "" with params "" to session "one" |
| 116 | + And we send Execute "" to session "one" |
| 117 | + And we send Sync to session "one" |
| 118 | + Then we verify backend_pid from session "one" is different from "first_pid" |
0 commit comments