-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathConcurrentTests.cs
More file actions
332 lines (298 loc) · 13 KB
/
Copy pathConcurrentTests.cs
File metadata and controls
332 lines (298 loc) · 13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#pragma warning disable CS8602 // Dereference of a possibly null reference.
namespace NpgsqlRestTests;
public static partial class Database
{
public static void ConcurrentTests()
{
script.Append("""
create function get_case_concurrent1(
_int_field int
)
returns table (
int_field int
)
language sql
as
$_$
select _int_field;
$_$;
create function get_case_concurrent2(
_text_field text,
_int_field int
)
returns table (
text_field text,
int_field int
)
language sql
as
$_$
select _text_field, _int_field;
$_$;
create function get_case_concurrent3(
_bool_field bool,
_int_field int,
_text_field text
)
returns table (
bool_field bool,
int_field int,
text_field text
)
language sql
as
$_$
select _bool_field, _int_field, _text_field;
$_$;
create function get_case_concurrent4(
_timestamp_field timestamp,
_bool_field bool,
_text_field text,
_int_field int
)
returns table (
timestamp_field timestamp,
bool_field bool,
text_field text,
int_field int
)
language sql
as
$_$
select _timestamp_field, _bool_field, _text_field, _int_field;
$_$;
create function get_case_concurrent5(
_int_array int[],
_timestamp_field timestamp,
_int_field int,
_bool_field bool,
_text_field text
)
returns table (
int_array int[],
timestamp_field timestamp,
int_field int,
bool_field bool,
text_field text
)
language sql
as
$_$
select _int_array, _timestamp_field, _int_field, _bool_field, _text_field;
$_$;
create function get_case_concurrent6(
_text_array text[],
_int_field int,
_bool_field bool,
_int_array int[],
_text_field text,
_timestamp_field timestamp
)
returns table (
text_array text[],
int_field int,
bool_field bool,
int_array int[],
text_field text,
timestamp_field timestamp
)
language sql
as
$_$
select _text_array, _int_field, _bool_field, _int_array, _text_field, _timestamp_field;
$_$;
create function get_case_concurrent7(
_bool_array bool[],
_text_field text,
_timestamp_field timestamp,
_int_array int[],
_int_field int,
_text_array text[],
_bool_field bool
)
returns table (
bool_array bool[],
text_field text,
timestamp_field timestamp,
int_array int[],
int_field int,
text_array text[],
bool_field bool
)
language sql
as
$_$
select _bool_array, _text_field, _timestamp_field, _int_array, _int_field, _text_array, _bool_field;
$_$;
create function get_case_concurrent8(
_timestamp_array timestamp[],
_bool_field bool,
_int_array int[],
_text_field text,
_bool_array bool[],
_timestamp_field timestamp,
_int_field int,
_text_array text[]
)
returns table (
timestamp_array timestamp[],
bool_field bool,
int_array int[],
text_field text,
bool_array bool[],
timestamp_field timestamp,
int_field int,
text_array text[]
)
language sql
as
$_$
select _timestamp_array, _bool_field, _int_array, _text_field, _bool_array, _timestamp_field, _int_field, _text_array;
$_$;
""");
}
}
[Collection("TestFixture")]
public class ConcurrentTests(TestFixture test)
{
[Fact]
public async Task Test_case_concurrent()
{
var tasks = new[]
{
Test_get_case_concurrent1(),
Test_get_case_concurrent2(),
Test_get_case_concurrent3(),
Test_get_case_concurrent4(),
Test_get_case_concurrent5(),
Test_get_case_concurrent6(),
Test_get_case_concurrent7(),
Test_get_case_concurrent8()
};
await Task.WhenAll(tasks);
}
private async Task Test_get_case_concurrent1()
{
var query = new QueryBuilder { { "intField", "123" } };
using var result = await test.Client.GetAsync($"/api/get-case-concurrent1/{query}");
var response = await result.Content.ReadAsStringAsync();
result?.StatusCode.Should().Be(HttpStatusCode.OK);
result.Content.Headers.ContentType.MediaType.Should().Be("application/json");
var array = JsonNode.Parse(response).AsArray();
array.Count.Should().Be(1);
array[0]["intField"].ToJsonString().Should().Be("123");
array[0].AsObject().Count.Should().Be(1);
}
private async Task Test_get_case_concurrent2()
{
var query = new QueryBuilder { { "textField", "test" }, { "intField", "123" } };
using var result = await test.Client.GetAsync($"/api/get-case-concurrent2/{query}");
var response = await result.Content.ReadAsStringAsync();
result?.StatusCode.Should().Be(HttpStatusCode.OK);
result.Content.Headers.ContentType.MediaType.Should().Be("application/json");
var array = JsonNode.Parse(response).AsArray();
array.Count.Should().Be(1);
array[0]["intField"].ToJsonString().Should().Be("123");
array[0]["textField"].ToJsonString().Should().Be("\"test\"");
array[0].AsObject().Count.Should().Be(2);
}
private async Task Test_get_case_concurrent3()
{
var query = new QueryBuilder { { "boolField", "true" }, { "intField", "123" }, { "textField", "test" } };
using var result = await test.Client.GetAsync($"/api/get-case-concurrent3/{query}");
var response = await result.Content.ReadAsStringAsync();
result?.StatusCode.Should().Be(HttpStatusCode.OK);
result.Content.Headers.ContentType.MediaType.Should().Be("application/json");
var array = JsonNode.Parse(response).AsArray();
array.Count.Should().Be(1);
array[0]["intField"].ToJsonString().Should().Be("123");
array[0]["textField"].ToJsonString().Should().Be("\"test\"");
array[0]["boolField"].ToJsonString().Should().Be("true");
array[0].AsObject().Count.Should().Be(3);
}
private async Task Test_get_case_concurrent4()
{
var query = new QueryBuilder { { "timestampField", "2024-01-01T12:00:00" }, { "boolField", "true" }, { "textField", "test" }, { "intField", "123" } };
using var result = await test.Client.GetAsync($"/api/get-case-concurrent4/{query}");
var response = await result.Content.ReadAsStringAsync();
result?.StatusCode.Should().Be(HttpStatusCode.OK);
result.Content.Headers.ContentType.MediaType.Should().Be("application/json");
var array = JsonNode.Parse(response).AsArray();
array.Count.Should().Be(1);
array[0]["intField"].ToJsonString().Should().Be("123");
array[0]["textField"].ToJsonString().Should().Be("\"test\"");
array[0]["boolField"].ToJsonString().Should().Be("true");
array[0]["timestampField"].ToJsonString().Should().Be("\"2024-01-01T12:00:00\"");
array[0].AsObject().Count.Should().Be(4);
}
private async Task Test_get_case_concurrent5()
{
var query = new QueryBuilder { { "intArray", "1" }, { "intArray", "2" }, { "intArray", "3" }, { "timestampField", "2024-01-01T12:00:00" }, { "intField", "123" }, { "boolField", "true" }, { "textField", "test" } };
using var result = await test.Client.GetAsync($"/api/get-case-concurrent5/{query}");
var response = await result.Content.ReadAsStringAsync();
result?.StatusCode.Should().Be(HttpStatusCode.OK);
result.Content.Headers.ContentType.MediaType.Should().Be("application/json");
var array = JsonNode.Parse(response).AsArray();
array.Count.Should().Be(1);
array[0]["intField"].ToJsonString().Should().Be("123");
array[0]["textField"].ToJsonString().Should().Be("\"test\"");
array[0]["boolField"].ToJsonString().Should().Be("true");
array[0]["timestampField"].ToJsonString().Should().Be("\"2024-01-01T12:00:00\"");
array[0]["intArray"].ToJsonString().Should().Be("[1,2,3]");
array[0].AsObject().Count.Should().Be(5);
}
private async Task Test_get_case_concurrent6()
{
var query = new QueryBuilder { { "textArray", "a" }, { "textArray", "b" }, { "textArray", "c" }, { "intField", "123" }, { "boolField", "true" }, { "intArray", "1" }, { "intArray", "2" }, { "intArray", "3" }, { "textField", "test" }, { "timestampField", "2024-01-01T12:00:00" } };
using var result = await test.Client.GetAsync($"/api/get-case-concurrent6/{query}");
var response = await result.Content.ReadAsStringAsync();
result?.StatusCode.Should().Be(HttpStatusCode.OK);
result.Content.Headers.ContentType.MediaType.Should().Be("application/json");
var array = JsonNode.Parse(response).AsArray();
array.Count.Should().Be(1);
array[0]["intField"].ToJsonString().Should().Be("123");
array[0]["textField"].ToJsonString().Should().Be("\"test\"");
array[0]["boolField"].ToJsonString().Should().Be("true");
array[0]["timestampField"].ToJsonString().Should().Be("\"2024-01-01T12:00:00\"");
array[0]["intArray"].ToJsonString().Should().Be("[1,2,3]");
array[0]["textArray"].ToJsonString().Should().Be("[\"a\",\"b\",\"c\"]");
array[0].AsObject().Count.Should().Be(6);
}
private async Task Test_get_case_concurrent7()
{
var query = new QueryBuilder { { "boolArray", "true" }, { "boolArray", "false" }, { "boolArray", "true" }, { "textField", "test" }, { "timestampField", "2024-01-01T12:00:00" }, { "intArray", "1" }, { "intArray", "2" }, { "intArray", "3" }, { "intField", "123" }, { "textArray", "a" }, { "textArray", "b" }, { "textArray", "c" }, { "boolField", "true" } };
using var result = await test.Client.GetAsync($"/api/get-case-concurrent7/{query}");
var response = await result.Content.ReadAsStringAsync();
result?.StatusCode.Should().Be(HttpStatusCode.OK);
result.Content.Headers.ContentType.MediaType.Should().Be("application/json");
var array = JsonNode.Parse(response).AsArray();
array.Count.Should().Be(1);
array[0]["intField"].ToJsonString().Should().Be("123");
array[0]["textField"].ToJsonString().Should().Be("\"test\"");
array[0]["boolField"].ToJsonString().Should().Be("true");
array[0]["timestampField"].ToJsonString().Should().Be("\"2024-01-01T12:00:00\"");
array[0]["intArray"].ToJsonString().Should().Be("[1,2,3]");
array[0]["textArray"].ToJsonString().Should().Be("[\"a\",\"b\",\"c\"]");
array[0]["boolArray"].ToJsonString().Should().Be("[true,false,true]");
array[0].AsObject().Count.Should().Be(7);
}
private async Task Test_get_case_concurrent8()
{
var query = new QueryBuilder { { "timestampArray", "2024-01-01T12:00:00" }, { "timestampArray", "2024-01-02T12:00:00" }, { "boolField", "true" }, { "intArray", "1" }, { "intArray", "2" }, { "intArray", "3" }, { "textField", "test" }, { "boolArray", "true" }, { "boolArray", "false" }, { "boolArray", "true" }, { "timestampField", "2024-01-01T12:00:00" }, { "intField", "123" }, { "textArray", "a" }, { "textArray", "b" }, { "textArray", "c" } };
using var result = await test.Client.GetAsync($"/api/get-case-concurrent8/{query}");
var response = await result.Content.ReadAsStringAsync();
result?.StatusCode.Should().Be(HttpStatusCode.OK);
result.Content.Headers.ContentType.MediaType.Should().Be("application/json");
var array = JsonNode.Parse(response).AsArray();
array.Count.Should().Be(1);
array[0]["intField"].ToJsonString().Should().Be("123");
array[0]["textField"].ToJsonString().Should().Be("\"test\"");
array[0]["boolField"].ToJsonString().Should().Be("true");
array[0]["timestampField"].ToJsonString().Should().Be("\"2024-01-01T12:00:00\"");
array[0]["intArray"].ToJsonString().Should().Be("[1,2,3]");
array[0]["textArray"].ToJsonString().Should().Be("[\"a\",\"b\",\"c\"]");
array[0]["boolArray"].ToJsonString().Should().Be("[true,false,true]");
array[0]["timestampArray"].ToJsonString().Should().Be("[\"2024-01-01T12:00:00\",\"2024-01-02T12:00:00\"]");
array[0].AsObject().Count.Should().Be(8);
}
}