Skip to content

Commit

Permalink
Updating cmap spec tests to account for race conditions
Browse files Browse the repository at this point in the history
Includes adding the waitForEvent operation, and
adjusting some tests to avoid race conditions.
  • Loading branch information
daprahamian committed Feb 25, 2019
1 parent 3b0f399 commit 9ab3b33
Show file tree
Hide file tree
Showing 19 changed files with 126 additions and 154 deletions.
9 changes: 8 additions & 1 deletion source/connection-monitoring-and-pooling/tests/README.rst
Expand Up @@ -64,10 +64,15 @@ Valid Unit Test Operations are the following:

- ``ms``: The number of milliseconds to sleep the current thread for

- ``waitFor(target)``: wait for thread ``target`` to finish executing. Propagate any errors to the main thread.
- ``waitForThread(target)``: wait for thread ``target`` to finish executing. Propagate any errors to the main thread.

- ``target``: The name of the thread to wait for.

- ``waitForEvent(event, count)``: block the current thread until ``event`` has occurred ``count`` times

- ``event``: The name of the event
- ``count``: The number of times the event must occur (counting from the start of the test)

- ``label = pool.checkOut()``: call ``checkOut`` on pool, returning the checked out connection

- ``label``: If specified, associate this label with the returned connection, so that it may be referenced in later operations
Expand Down Expand Up @@ -138,6 +143,8 @@ For each YAML file with ``style: unit``:
- Assert that ``actualEvents[idx]`` MATCHES ``expectedEvent``


It is important to note that the ``ignore`` list is used for calculating ``actualEvents``, but is NOT used for the ``waitForEvent`` command

Prose Tests
===========

Expand Down
Expand Up @@ -7,18 +7,10 @@
"name": "start",
"target": "thread1"
},
{
"name": "wait",
"ms": 10
},
{
"name": "start",
"target": "thread2"
},
{
"name": "wait",
"ms": 20
},
{
"name": "start",
"target": "thread3"
Expand All @@ -36,30 +28,30 @@
"thread": "thread3"
},
{
"name": "waitFor",
"name": "waitForThread",
"target": "thread1"
},
{
"name": "waitFor",
"name": "waitForThread",
"target": "thread2"
},
{
"name": "waitFor",
"name": "waitForThread",
"target": "thread3"
}
],
"events": [
{
"type": "ConnectionCheckedOut",
"connectionId": 1
"connectionId": 42
},
{
"type": "ConnectionCheckedOut",
"connectionId": 2
"connectionId": 42
},
{
"type": "ConnectionCheckedOut",
"connectionId": 3
"connectionId": 42
}
],
"ignore": [
Expand Down
Expand Up @@ -2,17 +2,10 @@ version: 1
style: unit
description: must be able to check out multiple connections at the same time
operations:
# Note: this test can be somewhat non-deterministic depending on how you
# implement your test runner. The sleep operations should make this more
# consistent.
- name: start
target: thread1
- name: wait
ms: 10
- name: start
target: thread2
- name: wait
ms: 10
- name: start
target: thread3
- name: checkOut
Expand All @@ -21,19 +14,19 @@ operations:
thread: thread2
- name: checkOut
thread: thread3
- name: waitFor
- name: waitForThread
target: thread1
- name: waitFor
- name: waitForThread
target: thread2
- name: waitFor
- name: waitForThread
target: thread3
events:
- type: ConnectionCheckedOut
connectionId: 1
connectionId: 42
- type: ConnectionCheckedOut
connectionId: 2
connectionId: 42
- type: ConnectionCheckedOut
connectionId: 3
connectionId: 42
ignore:
- ConnectionCreated
- ConnectionReady
Expand Down
Expand Up @@ -28,13 +28,6 @@
"address": 42,
"options": 42
},
{
"type": "ConnectionCreated",
"connectionId": 1
},
{
"type": "ConnectionCheckOutStarted"
},
{
"type": "ConnectionCheckedOut",
"connectionId": 1
Expand All @@ -43,24 +36,19 @@
"type": "ConnectionCheckedIn",
"connectionId": 1
},
{
"type": "ConnectionCheckOutStarted"
},
{
"type": "ConnectionClosed",
"connectionId": 1,
"reason": "idle"
},
{
"type": "ConnectionCreated",
"connectionId": 2
},
{
"type": "ConnectionCheckedOut",
"connectionId": 2
}
],
"ignore": [
"ConnectionReady"
"ConnectionReady",
"ConnectionCreated",
"ConnectionCheckOutStarted"
]
}
Expand Up @@ -15,21 +15,17 @@ events:
- type: ConnectionPoolCreated
address: 42
options: 42
- type: ConnectionCreated
connectionId: 1
- type: ConnectionCheckOutStarted
- type: ConnectionCheckedOut
connectionId: 1
- type: ConnectionCheckedIn
connectionId: 1
# In between these, wait so connection becomes idle
- type: ConnectionCheckOutStarted
- type: ConnectionClosed
connectionId: 1
reason: idle
- type: ConnectionCreated
connectionId: 2
- type: ConnectionCheckedOut
connectionId: 2
ignore:
- ConnectionReady
- ConnectionCreated
- ConnectionCheckOutStarted
Expand Up @@ -2,13 +2,14 @@
"version": 1,
"style": "unit",
"description": "must destroy and must not check out a stale connection if found while iterating available connections",
"poolOptions": {
"minPoolSize": 3
},
"operations": [
{
"name": "wait",
"ms": 20
"name": "checkOut",
"label": "conn"
},
{
"name": "checkIn",
"connection": "conn"
},
{
"name": "clear"
Expand All @@ -24,34 +25,30 @@
"options": 42
},
{
"type": "ConnectionPoolCleared",
"address": 42
"type": "ConnectionCheckedOut",
"connectionId": 1
},
{
"type": "ConnectionCheckOutStarted"
"type": "ConnectionCheckedIn",
"connectionId": 1
},
{
"type": "ConnectionClosed",
"connectionId": 42,
"reason": "stale"
},
{
"type": "ConnectionClosed",
"connectionId": 42,
"reason": "stale"
"type": "ConnectionPoolCleared",
"address": 42
},
{
"type": "ConnectionClosed",
"connectionId": 42,
"connectionId": 1,
"reason": "stale"
},
{
"type": "ConnectionCheckedOut",
"connectionId": 4
"connectionId": 2
}
],
"ignore": [
"ConnectionReady",
"ConnectionCreated",
"ConnectionReady"
"ConnectionCheckOutStarted"
]
}
@@ -1,34 +1,29 @@
version: 1
style: unit
description: must destroy and must not check out a stale connection if found while iterating available connections
poolOptions:
minPoolSize: 3
operations:
- name: wait
ms: 20
- name: checkOut
label: conn
- name: checkIn
connection: conn
- name: clear
- name: checkOut
events:
- type: ConnectionPoolCreated
address: 42
options: 42
- type: ConnectionCheckedOut
connectionId: 1
- type: ConnectionCheckedIn
connectionId: 1
- type: ConnectionPoolCleared
address: 42
- type: ConnectionCheckOutStarted

# Note: we cannot deterministically assert which connections get destroyed in which order,
# just that they will all be destroyed before connection check out.
- type: ConnectionClosed
connectionId: 42
reason: stale
- type: ConnectionClosed
connectionId: 42
reason: stale
- type: ConnectionClosed
connectionId: 42
connectionId: 1
reason: stale
- type: ConnectionCheckedOut
connectionId: 4
connectionId: 2
ignore:
- ConnectionCreated
- ConnectionReady
- ConnectionCreated
- ConnectionCheckOutStarted
Expand Up @@ -33,15 +33,16 @@
"thread": "thread1"
},
{
"name": "wait",
"ms": 10
"name": "waitForEvent",
"event": "ConnectionCheckOutStarted",
"count": 5
},
{
"name": "checkIn",
"connection": "conn1"
},
{
"name": "waitFor",
"name": "waitForThread",
"target": "thread1"
}
],
Expand Down
Expand Up @@ -16,11 +16,12 @@ operations:
target: thread1
- name: checkOut
thread: thread1
- name: wait
ms: 10
- name: waitForEvent
event: ConnectionCheckOutStarted
count: 5
- name: checkIn
connection: conn1
- name: waitFor
- name: waitForThread
target: thread1
events:
- type: ConnectionPoolCreated
Expand Down
Expand Up @@ -3,12 +3,13 @@
"style": "unit",
"description": "must be able to start a pool with minPoolSize connections",
"poolOptions": {
"minPoolSize": 5
"minPoolSize": 3
},
"operations": [
{
"name": "wait",
"ms": 50
"name": "waitForEvent",
"event": "ConnectionCreated",
"count": 3
},
{
"name": "checkOut"
Expand All @@ -32,24 +33,14 @@
"type": "ConnectionCreated",
"connectionId": 42
},
{
"type": "ConnectionCreated",
"connectionId": 42
},
{
"type": "ConnectionCreated",
"connectionId": 42
},
{
"type": "ConnectionCheckOutStarted"
},
{
"type": "ConnectionCheckedOut",
"connectionId": 42
}
],
"ignore": [
"ConnectionReady",
"ConnectionClosed"
"ConnectionClosed",
"ConnectionCheckOutStarted"
]
}

0 comments on commit 9ab3b33

Please sign in to comment.