Skip to content

Commit ff282c7

Browse files
authored
DRIVERS-1724 Add backgroundThreadIntervalMS pool option to CMAP test specification (#998)
DRIVERS-1724 Add `backgroundThreadIntervalMS` pool option to CMAP test specification Use the new option in `pool-checkout-no-idle.yml`, `pool-checkout-no-stale.yml` to disable background thread runs. Use the new option in `pool-clear-min-size.yml` and `pool-create-min-size-error.yml` to specify 50 ms delay between runs. DRIVERS-1724
1 parent 5141a89 commit ff282c7

10 files changed

+60
-29
lines changed

source/connection-monitoring-and-pooling/connection-monitoring-and-pooling.rst

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Connection Monitoring and Pooling
99
:Status: Accepted
1010
:Type: Standards
1111
:Minimum Server Version: N/A
12-
:Last Modified: 2021-04-12
13-
:Version: 1.5.0
12+
:Last Modified: 2021-06-02
13+
:Version: 1.5.1
1414

1515
.. contents::
1616

@@ -417,9 +417,9 @@ method MUST immediately return and MUST NOT emit a PoolReadyEvent.
417417
418418
mark pool as "ready"
419419
emit PoolReadyEvent
420-
resume background thread
420+
allow background thread to create connections
421421
422-
Note that resuming the background thread after emitting PoolReadyEvent is of the essence,
422+
Note that the PoolReadyEvent MUST be emitted before the background thread is allowed to resume creating new connections,
423423
and it must be the case that no observer is able to observe actions of the background thread
424424
related to creating new connections before observing the PoolReadyEvent event.
425425

@@ -736,12 +736,19 @@ A Pool SHOULD have a background Thread that is responsible for
736736
monitoring the state of all available `Connections <#connection>`_. This background
737737
thread SHOULD
738738

739-
- Populate `Connections <#connection>`_ to ensure that the pool always satisfies **minPoolSize**
740-
- The background thread SHOULD just go back to sleep instead of waiting for
741-
pendingConnectionCount to become less than maxConnecting when satisfying
742-
minPoolSize.
739+
- Populate `Connections <#connection>`_ to ensure that the pool always satisfies minPoolSize.
743740
- Remove and close perished available `Connections <#connection>`_.
744741

742+
Conceptually, the aforementioned activities are organized into sequential Background Thread Runs.
743+
A Run MUST do as much work as readily available and then end instead of waiting for more work.
744+
For example, instead of waiting for pendingConnectionCount to become less than maxConnecting when satisfying minPoolSize,
745+
a Run MUST either proceed with the rest of its duties, e.g., closing available perished connections, or end.
746+
747+
The duration of intervals between the end of one Run and the beginning of the next Run is not specified,
748+
but the
749+
`Test Format and Runner Specification <https://github.com/mongodb/specifications/tree/master/source/connection-monitoring-and-pooling/tests>`__
750+
may restrict this duration, or introduce other restrictions to facilitate testing.
751+
745752
withConnection
746753
^^^^^^^^^^^^^^
747754

@@ -1115,6 +1122,8 @@ Change log
11151122

11161123
:2021-4-12: Adding in behaviour for load balancer mode.
11171124

1125+
:2021-06-02: Formalize the behavior of a `Background Thread <#background-thread>`__.
1126+
11181127
.. Section for links.
11191128
11201129
.. _Application Errors: /source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#application-errors

source/connection-monitoring-and-pooling/tests/README.rst

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,20 @@ Unit Test Format:
3636

3737
All Unit Tests have some of the following fields:
3838

39-
- ``poolOptions``: if present, connection pool options to use when creating a pool
39+
- ``poolOptions``: If present, connection pool options to use when creating a pool;
40+
both `standard ConnectionPoolOptions <https://github.com/mongodb/specifications/blob/master/source/connection-monitoring-and-pooling/connection-monitoring-and-pooling.rst#connection-pool-options-1>`__
41+
and the following test-specific options are allowed:
42+
43+
- ``backgroundThreadIntervalMS``: A time interval between the end of a
44+
`Background Thread Run <https://github.com/mongodb/specifications/blob/master/source/connection-monitoring-and-pooling/connection-monitoring-and-pooling.rst#background-thread>`__
45+
and the beginning of the next Run. If a Connection Pool does not implement a Background Thread, the Test Runner MUST ignore the option.
46+
If the option is not specified, an implementation is free to use any value it finds reasonable.
47+
48+
Possible values (0 is not allowed):
49+
50+
- A negative value: never begin a Run.
51+
- A positive value: the interval between Runs in milliseconds.
52+
4053
- ``operations``: A list of operations to perform. All operations support the following fields:
4154

4255
- ``name``: A string describing which operation to issue.
@@ -155,8 +168,6 @@ For each YAML file with ``style: unit``:
155168

156169
- If ``poolOptions`` is specified, use those options to initialize both pools
157170
- The returned pool must have an ``address`` set as a string value.
158-
- If the pool uses a background thread to satisfy ``minPoolSize``, ensure it
159-
attempts to create a new connection every 50ms.
160171

161172
- Process each ``operation`` in ``operations`` (on the main thread)
162173

source/connection-monitoring-and-pooling/tests/pool-checkout-no-idle.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"style": "unit",
44
"description": "must destroy and must not check out an idle connection if found while iterating available connections",
55
"poolOptions": {
6-
"maxIdleTimeMS": 10
6+
"maxIdleTimeMS": 10,
7+
"backgroundThreadIntervalMS": -1
78
},
89
"operations": [
910
{
@@ -24,11 +25,6 @@
2425
{
2526
"name": "checkOut"
2627
},
27-
{
28-
"name": "waitForEvent",
29-
"event": "ConnectionClosed",
30-
"count": 1
31-
},
3228
{
3329
"name": "waitForEvent",
3430
"event": "ConnectionCheckedOut",
@@ -56,6 +52,11 @@
5652
"connectionId": 1,
5753
"reason": "idle",
5854
"address": 42
55+
},
56+
{
57+
"type": "ConnectionCheckedOut",
58+
"connectionId": 2,
59+
"address": 42
5960
}
6061
],
6162
"ignore": [

source/connection-monitoring-and-pooling/tests/pool-checkout-no-idle.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ style: unit
33
description: must destroy and must not check out an idle connection if found while iterating available connections
44
poolOptions:
55
maxIdleTimeMS: 10
6+
backgroundThreadIntervalMS: -1
67
operations:
78
- name: ready
89
- name: checkOut
@@ -12,9 +13,6 @@ operations:
1213
- name: wait
1314
ms: 50
1415
- name: checkOut
15-
- name: waitForEvent
16-
event: ConnectionClosed
17-
count: 1
1816
- name: waitForEvent
1917
event: ConnectionCheckedOut
2018
count: 2
@@ -33,6 +31,9 @@ events:
3331
connectionId: 1
3432
reason: idle
3533
address: 42
34+
- type: ConnectionCheckedOut
35+
connectionId: 2
36+
address: 42
3637
ignore:
3738
- ConnectionReady
3839
- ConnectionPoolReady

source/connection-monitoring-and-pooling/tests/pool-checkout-no-stale.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"version": 1,
33
"style": "unit",
44
"description": "must destroy and must not check out a stale connection if found while iterating available connections",
5+
"poolOptions": {
6+
"backgroundThreadIntervalMS": -1
7+
},
58
"operations": [
69
{
710
"name": "ready"
@@ -23,11 +26,6 @@
2326
{
2427
"name": "checkOut"
2528
},
26-
{
27-
"name": "waitForEvent",
28-
"event": "ConnectionClosed",
29-
"count": 1
30-
},
3129
{
3230
"name": "waitForEvent",
3331
"event": "ConnectionCheckedOut",
@@ -59,6 +57,11 @@
5957
"connectionId": 1,
6058
"reason": "stale",
6159
"address": 42
60+
},
61+
{
62+
"type": "ConnectionCheckedOut",
63+
"connectionId": 2,
64+
"address": 42
6265
}
6366
],
6467
"ignore": [

source/connection-monitoring-and-pooling/tests/pool-checkout-no-stale.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
version: 1
22
style: unit
33
description: must destroy and must not check out a stale connection if found while iterating available connections
4+
poolOptions:
5+
backgroundThreadIntervalMS: -1
46
operations:
57
- name: ready
68
- name: checkOut
@@ -10,9 +12,6 @@ operations:
1012
- name: clear
1113
- name: ready
1214
- name: checkOut
13-
- name: waitForEvent
14-
event: ConnectionClosed
15-
count: 1
1615
- name: waitForEvent
1716
event: ConnectionCheckedOut
1817
count: 2
@@ -32,6 +31,9 @@ events:
3231
connectionId: 1
3332
reason: stale
3433
address: 42
34+
- type: ConnectionCheckedOut
35+
connectionId: 2
36+
address: 42
3537
ignore:
3638
- ConnectionReady
3739
- ConnectionPoolReady

source/connection-monitoring-and-pooling/tests/pool-clear-min-size.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"style": "unit",
44
"description": "pool clear halts background minPoolSize establishments",
55
"poolOptions": {
6-
"minPoolSize": 1
6+
"minPoolSize": 1,
7+
"backgroundThreadIntervalMS": 50
78
},
89
"operations": [
910
{

source/connection-monitoring-and-pooling/tests/pool-clear-min-size.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ style: unit
33
description: pool clear halts background minPoolSize establishments
44
poolOptions:
55
minPoolSize: 1
6+
backgroundThreadIntervalMS: 50
67
operations:
78
- name: ready
89
- name: waitForEvent

source/connection-monitoring-and-pooling/tests/pool-create-min-size-error.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
},
2424
"poolOptions": {
2525
"minPoolSize": 1,
26+
"backgroundThreadIntervalMS": 50,
2627
"appName": "poolCreateMinSizeErrorTest"
2728
},
2829
"operations": [

source/connection-monitoring-and-pooling/tests/pool-create-min-size-error.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ failPoint:
1515
appName: "poolCreateMinSizeErrorTest"
1616
poolOptions:
1717
minPoolSize: 1
18+
backgroundThreadIntervalMS: 50
1819
appName: "poolCreateMinSizeErrorTest"
1920
operations:
2021
- name: ready

0 commit comments

Comments
 (0)