Skip to content

Commit

Permalink
✅ Update test for change stream [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
ujibang committed Feb 22, 2024
1 parent 82efe2e commit ecabeb1
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 15 deletions.
6 changes: 3 additions & 3 deletions core/src/test/java/karate/streams-setup.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ Scenario: Setup test environment
Given path db
And request {}
When method PUT
Then status 201
Then assert responseStatus == 201 || responseStatus == 200

# Step 2: Create test collection
* header Authorization = authHeader
Given path coll
And request {"streams": [{"stages": [], "uri": "changeStream" }, {"stages": [{"_$match": {"fullDocument.targettedProperty": {"_$var": "param"}}}], "uri": "changeStreamWithStageParam" }, {"stages":[{"_$match":{"fullDocument::name":"testname"}},{"_$match":{"_$or":[{"operationType":"insert"},{"operationType":"update"}]}}],"uri":"cs"},{"stages":[{"_$match":{"updateDescription::updatedFields::a":{"_$exists":true}}}],"uri":"ud"},{"stages":[{"_$match":{"operationType":"insert"}},{"_$addFields":{"fullDocument.div":{"_$divide":[1,"$fullDocument.n"]}}}],"uri":"testResume"}]}
When method PUT
Then status 201
Then assert responseStatus == 201 || responseStatus == 200

# Step 3: Create a secondary test collection
* header Authorization = authHeader
Given path anotherColl
And request {"streams": [{"stages": [], "missingUri": "missing" }]}
When method PUT
Then status 201
Then assert responseStatus == 201 || responseStatus == 200
80 changes: 68 additions & 12 deletions core/src/test/java/karate/streams.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
# WARNING: with karate v1.4.1 these scenarios hang
# it seems the socket does not disconnect after the scenario completes....

# Workaround to execute the scenarios follows:
# Workaround is forcing socket disconnection by RESTHeart. However if a test fails it hangs.

# Other workaroud is:

# 1) run restheart
# $ java -jar core/target/restheart.jar -o core/src/test/resources/etc/conf-overrides.yml

# 2) execute a single scenario
# $ cd core
# $ mvn test -Dtest=RunnerIT "-Dkarate.options=/Users/uji/development/restheart/core/src/test/java/karate/streams.feature:129"
# $ mvn test -Dtest=RunnerIT "-Dkarate.options=/Users/uji/development/restheart/core/src/test/java/karate/streams.feature:66"

# 3) let the scenario run. at the end it hangs...

Expand All @@ -24,7 +26,7 @@ Background:
* def db = '/test-change-streams'
* def coll = db + '/coll'
* def anotherColl = db + '/anotherColl'
* callonce read('./streams-setup.feature')
* call read('./streams-setup.feature')

* def sleep =
"""
Expand Down Expand Up @@ -60,7 +62,14 @@ Scenario: test insert (POST) new document (without avars)
* match result.fullDocument.a == 1
* match result.fullDocument.b == 2
* match result.fullDocument.c == 'test'
* socket.close()

# this is a workaround to force socket to disconnet (thanks to obsoleteChangeStreamRemover)
# otherwise the test hangs
* header Authorization = authHeader
Given path coll
And request {"streams": [] }
When method PUT
Then status 200

@requires-mongodb-3.6 @requires-replica-set
Scenario: test insert (POST) new document (with avars)
Expand All @@ -70,7 +79,7 @@ Scenario: test insert (POST) new document (with avars)
* def streamPath = '/_streams/changeStreamWithStageParam?avars={\'param\': \'test\'}'
* def baseUrl = 'http://localhost:8080'
* def host = baseUrl + encodeURI(coll + streamPath)
* def socket = karate.webSocket(host, undefined, { headers: { Authorization: 'Basic YWRtaW46c2VjcmV0' }})
* def socket = karate.webSocket(host, null, { headers: { Authorization: 'Basic YWRtaW46c2VjcmV0' }})
* call sleep 3

# This POST shouldn't be notified
Expand All @@ -93,6 +102,13 @@ Scenario: test insert (POST) new document (with avars)
* match result.fullDocument.targettedProperty == 'test'
* match result.fullDocument.anotherProp == 1

# this is a workaround to force socket to disconnet (thanks to obsoleteChangeStreamRemover)
# otherwise the test hangs
* header Authorization = authHeader
Given path coll
And request {"streams": [] }
When method PUT
Then status 200

@requires-mongodb-3.6 @requires-replica-set
Scenario: test PATCH on inserted document (without avars)
Expand All @@ -108,7 +124,7 @@ Scenario: test PATCH on inserted document (without avars)
Then def postLocation = responseHeaders['Location'][0]
Then status 201

* def socket = karate.webSocket(host, undefined, { headers: { Authorization: 'Basic YWRtaW46c2VjcmV0' }})
* def socket = karate.webSocket(host, null, { headers: { Authorization: 'Basic YWRtaW46c2VjcmV0' }})
* call sleep 3

* header Authorization = authHeader
Expand All @@ -124,6 +140,14 @@ Scenario: test PATCH on inserted document (without avars)
* match parsedMsg.updateDescription.updatedFields.anotherProp == 1
* match parsedMsg.updateDescription.removedFields contains "b"

# this is a workaround to force socket to disconnet (thanks to obsoleteChangeStreamRemover)
# otherwise the test hangs
* header Authorization = authHeader
Given url baseUrl
Given path coll
And request {"streams": [] }
When method PUT
Then status 200

@requires-mongodb-3.6 @requires-replica-set
Scenario: test PATCH on inserted document (with avars)
Expand All @@ -140,7 +164,7 @@ Scenario: test PATCH on inserted document (with avars)
Then status 201
* print location

* def socket = karate.webSocket(host, undefined, { headers: { Authorization: 'Basic YWRtaW46c2VjcmV0' }})
* def socket = karate.webSocket(host, null, { headers: { Authorization: 'Basic YWRtaW46c2VjcmV0' }})
* call sleep 3

* header Authorization = authHeader
Expand All @@ -157,6 +181,14 @@ Scenario: test PATCH on inserted document (with avars)
* match parsedMsg.updateDescription.updatedFields.anotherProp == 1
* match parsedMsg.updateDescription.removedFields contains "toBeRemoved"

# this is a workaround to force socket to disconnet (thanks to obsoleteChangeStreamRemover)
# otherwise the test hangs
* header Authorization = authHeader
Given url baseUrl
Given path coll
And request {"streams": [] }
When method PUT
Then status 200

@requires-mongodb-3.6 @requires-replica-set
Scenario: test PUT upserting notifications (without avars)
Expand All @@ -166,7 +198,7 @@ Scenario: test PUT upserting notifications (without avars)
* def streamPath = '/_streams/changeStream'
* def baseUrl = 'http://localhost:8080'
* def host = baseUrl + encodeURI(coll + streamPath)
* def socket = karate.webSocket(host, undefined, { headers: { Authorization: 'Basic YWRtaW46c2VjcmV0' }})
* def socket = karate.webSocket(host, null, { headers: { Authorization: 'Basic YWRtaW46c2VjcmV0' }})
* call sleep 3

* header Authorization = authHeader
Expand All @@ -189,7 +221,7 @@ Scenario: test PUT upserting notifications (without avars)
* def streamPath = '/_streams/changeStream'
* def baseUrl = 'http://localhost:8080'
* def host = baseUrl + encodeURI(coll + streamPath)
* def socket = karate.webSocket(host, undefined, { headers: { Authorization: 'Basic YWRtaW46c2VjcmV0' }})
* def socket = karate.webSocket(host, null, { headers: { Authorization: 'Basic YWRtaW46c2VjcmV0' }})
* call sleep 3

* header Authorization = authHeader
Expand All @@ -204,6 +236,14 @@ Scenario: test PUT upserting notifications (without avars)
* print parsedEditMsg
* match parsedEditMsg.operationType == 'replace'

# this is a workaround to force socket to disconnet (thanks to obsoleteChangeStreamRemover)
# otherwise the test hangs
* header Authorization = authHeader
Given path coll
And request {"streams": [] }
When method PUT
Then status 200


@requires-mongodb-3.6 @requires-replica-set
Scenario: test PUT upserting notifications (with avars)
Expand All @@ -213,7 +253,7 @@ Scenario: test PUT upserting notifications (with avars)
* def streamPath = '/_streams/changeStreamWithStageParam?avars={\'param\': \'test\'}'
* def baseUrl = 'http://localhost:8080'
* def host = baseUrl + encodeURI(coll + streamPath)
* def socket = karate.webSocket(host, undefined, { headers: { Authorization: 'Basic YWRtaW46c2VjcmV0' }})
* def socket = karate.webSocket(host, null, { headers: { Authorization: 'Basic YWRtaW46c2VjcmV0' }})
* call sleep 3

* header Authorization = authHeader
Expand All @@ -234,7 +274,7 @@ Scenario: test PUT upserting notifications (with avars)
* def streamPath = '/_streams/changeStream'
* def baseUrl = 'http://localhost:8080'
* def host = baseUrl + encodeURI(coll + streamPath)
* def socket = karate.webSocket(host, undefined, { headers: { Authorization: 'Basic YWRtaW46c2VjcmV0' }})
* def socket = karate.webSocket(host, null, { headers: { Authorization: 'Basic YWRtaW46c2VjcmV0' }})
* call sleep 3

* header Authorization = authHeader
Expand All @@ -249,6 +289,14 @@ Scenario: test PUT upserting notifications (with avars)
* print parsedEditMsg
* match parsedEditMsg.operationType == 'replace'

# this is a workaround to force socket to disconnet (thanks to obsoleteChangeStreamRemover)
# otherwise the test hangs
* header Authorization = authHeader
Given path coll
And request {"streams": [] }
When method PUT
Then status 200

@requires-mongodb-4 @requires-replica-set
Scenario: https://github.com/SoftInstigate/restheart/issues/414

Expand Down Expand Up @@ -307,4 +355,12 @@ Scenario: https://github.com/SoftInstigate/restheart/issues/415
* json thirdParsedMsg = listenResult
* print thirdParsedMsg
* match thirdParsedMsg.operationType == 'insert'
* match thirdParsedMsg.fullDocument.div == 0.5
* match thirdParsedMsg.fullDocument.div == 0.5

# this is a workaround to force socket to disconnet (thanks to obsoleteChangeStreamRemover)
# otherwise the test hangs
* header Authorization = authHeader
Given path coll
And request {"streams": [] }
When method PUT
Then status 200

0 comments on commit ecabeb1

Please sign in to comment.