Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 7fd4b18

Browse files
committed
Add test program to test violations
1 parent 6d718b1 commit 7fd4b18

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tests/ServiceStack.Text.TestsConsole/Program.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,51 @@
44

55
namespace ServiceStack.Text.TestsConsole
66
{
7+
public class T
8+
{
9+
public Guid X { get; set; }
10+
public char Y { get; set; }
11+
}
712

13+
class Program
14+
{
15+
static void Main(string[] args)
16+
{
17+
var violations = 0;
18+
const int count = 1000 * 1000;
19+
var json = new List<string>();
20+
var serializer = new JsonSerializer<T>();
21+
for (int i = 0; i < count; i++)
22+
{
23+
var t = new T
24+
{
25+
X = Guid.NewGuid(),
26+
Y = i % 2 == 0 ? 'C' : 'P',
27+
};
28+
json.Add(serializer.SerializeToString(t));
29+
}
30+
31+
var tasks = new List<Task>();
32+
for (int jj = 0; jj < 3; jj++)
33+
{
34+
int j = jj;
35+
tasks.Add(Task.Run(() => {
36+
for (int i = 0; i < count; i++)
37+
{
38+
string s = json[i];
39+
var t = serializer.DeserializeFromString(s);
40+
if (t.Y != (i % 2 == 0 ? 'C' : 'P'))
41+
{
42+
violations++;
43+
Console.WriteLine("Constraint violation index {0} thread {1} expected: {2} received: {3} json: {4}",
44+
i, j, i % 2 == 0 ? 'C' : 'P', t.Y, s);
45+
}
46+
}
47+
}));
48+
}
49+
tasks.ForEach(task => task.Wait());
50+
51+
Console.WriteLine($"There were {violations} viloations");
52+
}
53+
}
854
}

0 commit comments

Comments
 (0)