Skip to content

Commit 2f79dd8

Browse files
committed
Added concurrency test for #3174
1 parent 2e3f9fc commit 2f79dd8

File tree

1 file changed

+73
-25
lines changed

1 file changed

+73
-25
lines changed

src/integration-test/groovy/au/org/ala/fieldcapture/ParatooIntegrationSpec.groovy

+73-25
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import org.apache.http.HttpStatus
88
import spock.lang.Stepwise
99
import pages.RlpProjectPage
1010

11+
import java.util.concurrent.Callable
12+
import java.util.concurrent.ExecutorService
13+
import java.util.concurrent.Executors
14+
1115
@Stepwise
1216
// We need GrailsUnitTest because the WebService class has a dependency on grailsApplication.config
1317
// It slows startup down quite a bit though
@@ -27,6 +31,36 @@ class ParatooIntegrationSpec extends StubbedCasSpec implements GrailsUnitTest {
2731
webService = new WebService(grailsApplication: getGrailsApplication())
2832
}
2933

34+
private Map buildMintCollectionIdPayload() {
35+
[
36+
"survey_metadata": [
37+
"survey_details": [
38+
"survey_model": "soil-pit-characterisation-full",
39+
"time": "2023-08-28T00:34:13.100Z",
40+
"uuid": "123-123-123-123-123",
41+
"project_id": "monitorProject",
42+
"protocol_id": "guid-1",
43+
"protocol_version": "1"
44+
],
45+
"provenance":[
46+
"version_app": "0.0.1-xxxxx",
47+
"version_core": "0.1.0-1fb53f81",
48+
"version_core_documentation": "0.0.1-xxxxx",
49+
"version_org": "4.4-SNAPSHOT",
50+
"system_app": "monitor",
51+
"system_core": "Monitor-dummy-data-production",
52+
"system_org": "MERIT"
53+
]
54+
]
55+
]
56+
}
57+
58+
private Map mintCollectionId(Map payload, String token) {
59+
String url = testConfig.ecodata.baseUrl + 'paratoo/mintCollectionId'
60+
Map headers = ["Authorization": "Bearer ${token}"]
61+
Map resp = webService.post(url, payload, null, ContentType.APPLICATION_JSON, false, false, headers)
62+
resp
63+
}
3064

3165
def "Add new data set in to project"() {
3266

@@ -54,28 +88,7 @@ class ParatooIntegrationSpec extends StubbedCasSpec implements GrailsUnitTest {
5488
]
5589

5690
]
57-
Map mintCollectionIdPayload = [
58-
"survey_metadata": [
59-
"survey_details": [
60-
"survey_model": "soil-pit-characterisation-full",
61-
"time": "2023-08-28T00:34:13.100Z",
62-
"uuid": "123-123-123-123-123",
63-
"project_id": "monitorProject",
64-
"protocol_id": "guid-1",
65-
"protocol_version": "1"
66-
],
67-
"provenance":[
68-
"version_app": "0.0.1-xxxxx",
69-
"version_core": "0.1.0-1fb53f81",
70-
"version_core_documentation": "0.0.1-xxxxx",
71-
"version_org": "4.4-SNAPSHOT",
72-
"system_app": "monitor",
73-
"system_core": "Monitor-dummy-data-production",
74-
"system_org": "MERIT"
75-
]
76-
]
77-
]
78-
91+
Map mintCollectionIdPayload = buildMintCollectionIdPayload()
7992

8093
Map collectionPayload = [
8194
"coreProvenance": [
@@ -93,9 +106,7 @@ class ParatooIntegrationSpec extends StubbedCasSpec implements GrailsUnitTest {
93106
resp.statusCode == HttpStatus.SC_OK
94107

95108
when:
96-
url = testConfig.ecodata.baseUrl + 'paratoo/mintCollectionId'
97-
headers = ["Authorization": "Bearer ${token}"]
98-
resp = webService.post(url, mintCollectionIdPayload, null, ContentType.APPLICATION_JSON, false, false, headers)
109+
resp = mintCollectionId(mintCollectionIdPayload, token)
99110

100111
String orgMintedIdentifier = resp.resp.orgMintedIdentifier
101112
byte[] jsonBytes = orgMintedIdentifier.decodeBase64()
@@ -139,4 +150,41 @@ class ParatooIntegrationSpec extends StubbedCasSpec implements GrailsUnitTest {
139150
then: "The data set is displayed"
140151
datasetDetails.dataSetSummaryCount() == 1
141152
}
153+
154+
def "Paratoo data sets can be submitted concurrently without data errors"() {
155+
setup:
156+
ExecutorService executor = Executors.newFixedThreadPool(20)
157+
String token = tokenForUser('1')
158+
String projectId = 'monitorProject'
159+
160+
when:
161+
List callables = []
162+
for (int i = 0; i < 100; i++) {
163+
Callable callable = new Callable() {
164+
@Override
165+
Object call() throws Exception {
166+
Map payload = buildMintCollectionIdPayload()
167+
payload.survey_metadata.protocol_id = "guid-${i}"
168+
Map result = mintCollectionId(payload, token)
169+
170+
return result
171+
}
172+
}
173+
callables.add(callable)
174+
}
175+
executor.invokeAll(callables)
176+
177+
String url = testConfig.ecodata.baseUrl + 'project/'+projectId
178+
Map resp = webService.get(url)
179+
180+
181+
then:
182+
resp.resp?.custom?.dataSets?.size() == 101
183+
for (int i = 0; i < 100; i++) {
184+
resp.resp.custom.dataSets.find { it.surveyId.survey_metadata.protocol_id == 'guid-' + i } != null
185+
}
186+
187+
}
188+
189+
142190
}

0 commit comments

Comments
 (0)