-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBenchmarkTests.cs
More file actions
142 lines (128 loc) · 4.49 KB
/
BenchmarkTests.cs
File metadata and controls
142 lines (128 loc) · 4.49 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
using Xunit;
using System.IO;
using System.Threading.Tasks;
namespace Foundation.Data.Doublets.Cli.Tests
{
public class BenchmarkTests
{
[Fact]
public async Task BenchmarkRunner_ShouldRunSuccessfully()
{
// Arrange
var tempDbPath = Path.GetTempFileName();
try
{
var benchmarkRunner = new BenchmarkRunner(tempDbPath, trace: false);
var options = new BenchmarkOptions
{
TestQueries = new List<string> { "() ((1 1))" }, // Simple create operation
IterationsPerQuery = 2,
WarmupIterations = 1,
ServerPort = 8081 // Use different port to avoid conflicts
};
// Act
var results = await benchmarkRunner.RunBenchmarkAsync(options);
// Assert
Assert.NotNull(results);
Assert.NotNull(results.CliResults);
Assert.NotNull(results.ServerResults);
Assert.True(results.CliResults.TotalOperations > 0);
Assert.True(results.ServerResults.TotalOperations > 0);
Assert.True(results.CliResults.OverallAverageLatencyMs >= 0);
Assert.True(results.ServerResults.OverallAverageLatencyMs >= 0);
}
finally
{
if (File.Exists(tempDbPath))
{
File.Delete(tempDbPath);
}
}
}
[Fact]
public void BenchmarkOptions_ShouldHaveDefaults()
{
// Arrange & Act
var options = new BenchmarkOptions();
// Assert
Assert.NotNull(options.TestQueries);
Assert.Empty(options.TestQueries);
Assert.Equal(10, options.IterationsPerQuery);
Assert.Equal(3, options.WarmupIterations);
Assert.Equal(8080, options.ServerPort);
}
[Fact]
public void BenchmarkResults_ShouldPrintReport()
{
// Arrange
var results = new BenchmarkResults
{
CliResults = new AccessMethodResults
{
MethodName = "CLI Test",
TotalOperations = 10,
SuccessfulOperations = 10,
FailedOperations = 0,
OverallAverageLatencyMs = 5.0
},
ServerResults = new AccessMethodResults
{
MethodName = "Server Test",
TotalOperations = 10,
SuccessfulOperations = 8,
FailedOperations = 2,
OverallAverageLatencyMs = 10.0
}
};
// Act & Assert - Should not throw
results.PrintReport();
}
[Fact]
public void LinoProtocolClient_ShouldConnectAndDisconnect()
{
// Arrange
var client = new LinoProtocolClient("localhost", 8082);
// Act & Assert - Should not throw when disposing without connecting
client.Dispose();
// Test multiple dispose calls
client.Dispose();
}
[Fact]
public void LinoRequest_ShouldHaveProperties()
{
// Arrange & Act
var request = new LinoRequest
{
Query = "() ((1 1))",
RequestId = 123,
Timestamp = DateTime.UtcNow
};
// Assert
Assert.Equal("() ((1 1))", request.Query);
Assert.Equal(123, request.RequestId);
Assert.True(request.Timestamp != default);
}
[Fact]
public void LinoResponse_ShouldHaveProperties()
{
// Arrange & Act
var response = new LinoResponse
{
Success = true,
ProcessingTimeMs = 42,
ChangesCount = 1,
Changes = new List<ChangeInfo>
{
new ChangeInfo { Before = null, After = "(1: 1 1)" }
}
};
// Assert
Assert.True(response.Success);
Assert.Equal(42, response.ProcessingTimeMs);
Assert.Equal(1, response.ChangesCount);
Assert.Single(response.Changes);
Assert.Null(response.Changes[0].Before);
Assert.Equal("(1: 1 1)", response.Changes[0].After);
}
}
}