forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
teamcity.build
464 lines (408 loc) · 21.4 KB
/
teamcity.build
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
<?xml version="1.0" ?>
<project name="NHibernate TeamCity Build" xmlns="http://nant.sf.net/release/0.90/nant.xsd" default="clean-configure-test" xsi:schemaLocation="http://nant.sf.net/release/0.90/nant.xsd Tools\nant\schema\nant.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<property name="root.dir" value="." />
<property name="config.teamcity" value="default"/>
<property name="current-test-configuration.dir" value="${root.dir}/current-test-configuration" />
<property name="skip.db-service" value="true" overwrite="false" />
<include buildfile="${root.dir}/default.build" />
<if test="${not property::exists('CCNetLabel') and not property::exists('build.number')}">
<fail message="This build file is for use with CruiseControl.NET or TeamCity" />
</if>
<property name="build.number" value="${CCNetLabel}" if="${property::exists('CCNetLabel')}" />
<target name="clean-configure-test" depends="cleanall init copy-teamcity-configuration binaries start-db-service test stop-db-service verify-test-results binaries-zip" />
<target name="start-db-service" unless="${skip.db-service or not property::exists('db-service')}">
<servicecontroller action="Start" service="${db-service}" timeout="120000" />
</target>
<target name="stop-db-service" unless="${skip.db-service or not property::exists('db-service')}">
<servicecontroller action="Stop" service="${db-service}" timeout="120000" />
</target>
<target name="copy-teamcity-configuration">
<copy file="build-common/teamcity-hibernate.cfg.xml" tofile="${current-test-configuration.dir}/hibernate.cfg.xml" />
<call target="setup-teamcity-${config.teamcity}"/>
<property name="app.config" value="${current-test-configuration.dir}/hibernate.cfg.xml" />
<call target="put-connection-settings-into-defined-app-config" />
</target>
<target name="verify-test-results">
<if test="${property::exists('NHibernate.Test.IgnoreFail')}">
<!-- Process the current results first, so that these will be available in build artifacts even
if the last-result files is missing. -->
<property name="teamcity.current.result" value="${testResult::StripTimings(testresults.dir + '/NHibernate.Test.dll-results.xml', 'NHibernate.Test.current-results.xml')}" />
<copy file="${teamcity.last.result}" todir="${testresults.dir}" />
<property name="teamcity.report" value="${testResult::CompareResults(teamcity.current.result, teamcity.last.result)}" />
</if>
</target>
<target name="setup-teamcity-default">
<property name="db-service" value="MSSQL$SQLEXPRESS" />
<!-- default (SQL Server) does not require any additional settings/binaries -->
</target>
<target name="setup-teamcity-sqlServerOdbc">
<property name="db-service" value="MSSQL$SQLEXPRESS" />
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.OdbcDriver" />
<property name="nhibernate.odbc.explicit_datetime_scale" value="3" />
<!-- We need to use a dialect that avoids mapping DbType.Time to TIME on MSSQL. On modern SQL Server
this becomes TIME(7). Later, such values cannot be read back over ODBC. The
error we get is "System.ArgumentException : Unknown SQL type - SS_TIME_EX.". I don't know for certain
why this occurs, but MS docs do say that for a client "compiled using a version of SQL Server Native
Client prior to SQL Server 2008", TIME(7) cannot be converted back to the client. Assuming that .Net's
OdbcDriver would be considered a "client compiled with a previous version", it would make sense. Anyway,
using the MsSql2005Dialect avoids these test failures. -->
<property name="nhibernate.dialect" value="NHibernate.Dialect.MsSql2005Dialect" />
<!-- The OdbcDriver inherits SupportsMultipleOpenReaders=true from DriverBase, which requires Mars_Connection=yes for SQL Server. -->
<property name="nhibernate.connection.connection_string" value="Driver={SQL Server Native Client 11.0};Server=.\SQLExpress;Database=nhibernateOdbc;Trusted_Connection=yes;Mars_Connection=yes;" />
</target>
<target name="setup-teamcity-sqlServer-Sql2008ClientDriver">
<property name="db-service" value="MSSQL$SQLEXPRESS" />
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.Sql2008ClientDriver" />
</target>
<target name="setup-teamcity-sqlServer2012">
<property name="db-service" value="MSSQL$SQLEXPRESS" />
<property name="nhibernate.dialect" value="NHibernate.Dialect.MsSql2012Dialect" />
</target>
<target name="setup-teamcity-sqlServerCe32">
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.SqlServerCeDriver" />
<property name="nhibernate.dialect" value="NHibernate.Dialect.MsSqlCe40Dialect" />
<property name="nhibernate.connection.connection_string" value="Data Source=NHibernate.sdf" />
<property name="nhibernate.command_timeout" value="0" />
</target>
<target name="setup-teamcity-sqlServerCe64">
<property name="nunit-x64" value="true" />
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.SqlServerCeDriver" />
<property name="nhibernate.dialect" value="NHibernate.Dialect.MsSqlCe40Dialect" />
<property name="nhibernate.connection.connection_string" value="Data Source=NHibernate.sdf" />
<property name="nhibernate.command_timeout" value="0" />
</target>
<target name="setup-teamcity-firebird32">
<property name="db-service" value="FirebirdServerDefaultInstance" />
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.FirebirdClientDriver" />
<property name="nhibernate.dialect" value="NHibernate.Dialect.FirebirdDialect" />
<property name="nhibernate.connection.connection_string" value="DataSource=localhost;Database=nhibernate;User ID=SYSDBA;Password=masterkey;MaxPoolSize=200;charset=utf8;" />
</target>
<target name="setup-teamcity-firebird64">
<property name="db-service" value="FirebirdServerDefaultInstance" />
<property name="nunit-x64" value="true" />
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.FirebirdClientDriver" />
<property name="nhibernate.dialect" value="NHibernate.Dialect.FirebirdDialect" />
<property name="nhibernate.connection.connection_string" value="DataSource=localhost;Database=nhibernate;User ID=SYSDBA;Password=masterkey;MaxPoolSize=200;charset=utf8;" />
</target>
<target name="setup-teamcity-sqlite32">
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.SQLite20Driver" />
<!-- DateTimeFormatString allows to prevent storing the fact that written date was having kind UTC,
which dodges the undesirable time conversion to local done on reads by System.Data.SQLite.
See https://system.data.sqlite.org/index.html/tktview/44a0955ea344a777ffdbcc077831e1adc8b77a36
and https://github.com/nhibernate/nhibernate-core/issues/1362 -->
<property name="nhibernate.dialect" value="NHibernate.Dialect.SQLiteDialect" />
<property name="nhibernate.connection.connection_string" value="Data Source=NHibernate.db;DateTimeFormatString=yyyy-MM-dd HH:mm:ss.FFFFFFF;" />
</target>
<target name="setup-teamcity-sqlite64">
<property name="nunit-x64" value="true" />
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.SQLite20Driver" />
<!-- DateTimeFormatString allows to prevent storing the fact that written date was having kind UTC,
which dodges the undesirable time conversion to local done on reads by System.Data.SQLite.
See https://system.data.sqlite.org/index.html/tktview/44a0955ea344a777ffdbcc077831e1adc8b77a36
and https://github.com/nhibernate/nhibernate-core/issues/1362 -->
<property name="nhibernate.dialect" value="NHibernate.Dialect.SQLiteDialect" />
<property name="nhibernate.connection.connection_string" value="Data Source=NHibernate.db;DateTimeFormatString=yyyy-MM-dd HH:mm:ss.FFFFFFF;" />
</target>
<target name="setup-teamcity-postgresql">
<property name="db-service" value="postgresql-x64-10" />
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.NpgsqlDriver" />
<property name="nhibernate.dialect" value="NHibernate.Dialect.PostgreSQL83Dialect" />
<property name="nhibernate.connection.connection_string" value="Host=localhost;Port=5432;Database=nhibernate;Username=nhibernate;Password=nhibernate;Enlist=true" />
</target>
<target name="setup-teamcity-oracle">
<property name="db-service" value="OracleServiceXE" />
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.OracleClientDriver" />
<property name="nhibernate.dialect" value="NHibernate.Dialect.Oracle10gDialect" />
<property name="nhibernate.connection.connection_string" value="User ID=nhibernate;Password=nhibernate;Data Source=XE" />
<property name="NHibernate.Test.IgnoreFail" value="true" />
<property name="teamcity.last.result" value="${root.dir}/lib/teamcity/oracle/NHibernate.Test.last-results.xml" />
</target>
<target name="setup-teamcity-oracle32">
<property name="db-service" value="OracleServiceXE" />
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.OracleDataClientDriver" />
<property name="nhibernate.dialect" value="NHibernate.Dialect.Oracle10gDialect" />
<property name="nhibernate.connection.connection_string" value="User ID=nhibernate;Password=nhibernate;Metadata Pooling=false;Self Tuning=false;Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)))" />
<!-- Teamcity Oracle test database is configured with a non-Unicode encoding -->
<property name="nhibernate.oracle.use_n_prefixed_types_for_unicode" value="true" />
<!-- The default value of 4000 is too big for nvarchar2 with default database settings.
nvarchar2 may be used due to use_n_prefixed_types_for_unicode -->
<property name="nhibernate.query.default_cast_length" value="2000" />
<copy todir="${current-test-configuration.dir}">
<fileset basedir="${root.dir}/lib/teamcity/oracle/x86">
<include name="*.dll"/>
</fileset>
</copy>
<property name="NHibernate.Test.IgnoreFail" value="true" />
<property name="teamcity.last.result" value="${root.dir}/lib/teamcity/oracle/NHibernate.Test.last-results.xml" />
</target>
<target name="setup-teamcity-oracle64">
<property name="db-service" value="OracleServiceXE" />
<property name="nunit-x64" value="true" />
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.OracleDataClientDriver" />
<property name="nhibernate.dialect" value="NHibernate.Dialect.Oracle10gDialect" />
<property name="nhibernate.connection.connection_string" value="User ID=nhibernate;Password=nhibernate;Metadata Pooling=false;Self Tuning=false;Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)))" />
<!-- Teamcity Oracle test database is configured with a non-Unicode encoding -->
<property name="nhibernate.oracle.use_n_prefixed_types_for_unicode" value="true" />
<!-- The default value of 4000 is too big for nvarchar2 with default database settings.
nvarchar2 may be used due to use_n_prefixed_types_for_unicode -->
<property name="nhibernate.query.default_cast_length" value="2000" />
<copy todir="${current-test-configuration.dir}">
<fileset basedir="${root.dir}/lib/teamcity/oracle/x64">
<include name="*.dll"/>
</fileset>
</copy>
<property name="NHibernate.Test.IgnoreFail" value="true" />
<property name="teamcity.last.result" value="${root.dir}/lib/teamcity/oracle/NHibernate.Test.last-results.xml" />
</target>
<target name="setup-teamcity-oracle-managed32">
<property name="db-service" value="OracleServiceXE" />
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.OracleManagedDataClientDriver" />
<property name="nhibernate.dialect" value="NHibernate.Dialect.Oracle10gDialect" />
<property name="nhibernate.connection.connection_string" value="User ID=nhibernate;Password=nhibernate;Metadata Pooling=false;Self Tuning=false;Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)))" />
<!-- Teamcity Oracle test database is configured with a non-Unicode encoding -->
<property name="nhibernate.oracle.use_n_prefixed_types_for_unicode" value="true" />
<!-- The default value of 4000 is too big for nvarchar2 with default database settings.
nvarchar2 may be used due to use_n_prefixed_types_for_unicode -->
<property name="nhibernate.query.default_cast_length" value="2000" />
</target>
<target name="setup-teamcity-oracle-managed64">
<property name="db-service" value="OracleServiceXE" />
<property name="nunit-x64" value="true" />
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.OracleManagedDataClientDriver" />
<property name="nhibernate.dialect" value="NHibernate.Dialect.Oracle10gDialect" />
<property name="nhibernate.connection.connection_string" value="User ID=nhibernate;Password=nhibernate;Metadata Pooling=false;Self Tuning=false;Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)))" />
<!-- Teamcity Oracle test database is configured with a non-Unicode encoding -->
<property name="nhibernate.oracle.use_n_prefixed_types_for_unicode" value="true" />
<!-- The default value of 4000 is too big for nvarchar2 with default database settings.
nvarchar2 may be used due to use_n_prefixed_types_for_unicode -->
<property name="nhibernate.query.default_cast_length" value="2000" />
</target>
<target name="setup-teamcity-mysql">
<property name="db-service" value="MySQL57" />
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.MySqlDataDriver" />
<property name="nhibernate.dialect" value="NHibernate.Dialect.MySQL5Dialect" />
<property name="nhibernate.connection.connection_string" value="Data Source=localhost;Database=nhibernate;User ID=nhibernate;Password=nhibernate;Protocol=memory;Old Guids=True;" />
</target>
<target name="setup-teamcity-sqlanywhere">
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.SapSQLAnywhere17Driver" />
<property name="nhibernate.dialect" value="NHibernate.Dialect.SapSQLAnywhere17Dialect" />
<property name="nhibernate.connection.connection_string" value="UID=nhibernate;PWD=nhibernate;ServerName=nhibernate;DBN=nhibernate;DBF=sqlAnywhere.db;Enlist=false;" />
</target>
<script language="C#" prefix="testResult">
<references>
<include name="System.dll" />
<include name="System.Core.dll" />
<include name="System.Data.dll" />
<include name="System.Xml.dll" />
</references>
<imports>
<import namespace="System.Collections.Generic"/>
<import namespace="System.Data"/>
<import namespace="System.Data.Common"/>
<import namespace="System.Data.SqlClient"/>
<import namespace="System.IO"/>
<import namespace="System.Linq"/>
<import namespace="System.Xml"/>
</imports>
<code>
<![CDATA[
public static void StripAttributes(XmlDocument source, string xpath)
{
foreach (XmlAttribute att in source.SelectNodes(xpath))
att.OwnerElement.RemoveAttribute(att.Name);
}
public static void StripElements(XmlDocument source, string xpath)
{
foreach (XmlElement el in source.SelectNodes(xpath))
el.ParentNode.RemoveChild(el);
}
[Function("StripTimings")]
public static string StripTimings(string testResultFile, string outputFile)
{
try
{
XmlDocument testResults = new XmlDocument();
testResults.Load(testResultFile);
StripElements(testResults, "//stack-trace");
StripAttributes(testResults, "//@cwd");
StripAttributes(testResults, "//@total");
StripAttributes(testResults, "//@date");
StripAttributes(testResults, "//@time");
StripAttributes(testResults, "//@machine-name");
StripAttributes(testResults, "//@user");
StripAttributes(testResults, "//@user-domain");
outputFile = Path.GetDirectoryName(testResultFile) + "/" + outputFile;
testResults.Save(outputFile);
return outputFile;
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
public enum ResultStatus
{
None,
Failure,
Ignored,
Inconclusive,
Success
}
public class Result
{
public string Name;
public ResultStatus Status;
public bool Executed;
public bool Success;
public bool Inconclusive
{
get
{
return Executed && !Success && (Status == ResultStatus.Success || Status == ResultStatus.Inconclusive);
}
}
private static Result Parse(XmlNode testCase)
{
var result = new Result
{
Name = testCase.Attributes["name"].Value,
Executed = bool.Parse(testCase.Attributes["executed"].Value)
};
ResultStatus status;
Enum.TryParse<ResultStatus>(testCase.Attributes["result"].Value, out status);
result.Status = status;
if (result.Executed)
result.Success = bool.Parse(testCase.Attributes["success"].Value);
return result;
}
public override string ToString()
{
var prefix = "IGNORED - ";
if (Executed)
prefix = Success ? "PASS - " :
Inconclusive ? "INCONCL - " : "FAIL - ";
return prefix + Name;
}
public static IList<Result> ParseFile(string file)
{
var run1 = new XmlDocument();
run1.Load(file);
var results = new List<Result>();
foreach (XmlNode testCase in run1.SelectNodes("//test-case"))
{
var result = Parse(testCase);
results.Add(result);
}
return results;
}
}
[Function("CompareResults")]
public static string CompareResults(string currentResult, string lastResult)
{
try
{
var outputFile = Path.Combine(Path.GetDirectoryName(currentResult), "Comparison.txt");
var report = new StringBuilder();
report.AppendLine("Comparison Results");
report.AppendLine("==================");
var before = Result.ParseFile(lastResult);
var beforeByName = before
// Some multi-value tests may be duplicated
.GroupBy(b => b.Name)
.ToDictionary(
g => g.Key,
// Take one, preferably not failing first, thus ensuring an after failing test
// will be match as broken in case one of the dup was not failing.
g => g
// Succeeded
.OrderByDescending(r => r.Success)
// Else ignored
.ThenBy(r => r.Executed)
// Else inconclusive
.ThenBy(r => r.Inconclusive ? 0 : 1)
.First());
var after = Result.ParseFile(currentResult);
var newFailingTests = new List<Result>();
var newInconclusiveTests = new List<Result>();
var newNotFailingTests = new List<Result>();
var fixedTests = new List<Result>();
var ignoredTests = new List<Result>();
var brokenTests = new List<Result>();
var inconclusiveTests = new List<Result>();
var afterTestNames = new HashSet<string>();
foreach (var afterResult in after)
{
afterTestNames.Add(afterResult.Name);
Result beforeResult;
if (beforeByName.TryGetValue(afterResult.Name, out beforeResult))
{
if (!beforeResult.Success && afterResult.Success)
fixedTests.Add(afterResult);
if (beforeResult.Executed && !afterResult.Executed)
ignoredTests.Add(afterResult);
if (beforeResult.Success && afterResult.Executed && !afterResult.Success)
{
if (afterResult.Inconclusive)
inconclusiveTests.Add(afterResult);
else
brokenTests.Add(afterResult);
}
if (beforeResult.Inconclusive && afterResult.Executed && !afterResult.Success && !afterResult.Inconclusive)
brokenTests.Add(afterResult);
}
else
{
if (afterResult.Executed && !afterResult.Success)
{
if (afterResult.Inconclusive)
newInconclusiveTests.Add(afterResult);
else
newFailingTests.Add(afterResult);
}
else
newNotFailingTests.Add(afterResult);
}
}
var missingTests = new List<Result>();
foreach (var result in before)
if (!afterTestNames.Contains(result.Name))
missingTests.Add(result);
ReportResultGroup(report, brokenTests, "Tests broken since last recorded results");
ReportResultGroup(report, newFailingTests, "Tests new (failed) since last recorded results");
ReportResultGroup(report, inconclusiveTests, "Tests inconclusive since last recorded results");
ReportResultGroup(report, newInconclusiveTests, "Tests new (inconclusive) since last recorded results");
ReportResultGroup(report, fixedTests, "Tests fixed since last recorded results");
ReportResultGroup(report, ignoredTests, "Tests ignored since last recorded results");
ReportResultGroup(report, newNotFailingTests, "Tests new (not failing) since last recorded results");
ReportResultGroup(report, missingTests, "Tests missing since last recorded results");
var output = report.ToString();
File.WriteAllText(outputFile, output);
if (brokenTests.Count > 0)
throw new Exception("Previously passing tests have been broken\n\n" + output);
if (newFailingTests.Count > 0)
throw new Exception("New tests that fail have been added\n\n" + output);
return output;
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
public static void ReportResultGroup(StringBuilder report, IList<Result> resultGroup, string groupTitle)
{
report.AppendLine();
report.Append("*** ").Append(groupTitle).AppendLine(" ***");
if (resultGroup.Count > 0)
{
foreach (var result in resultGroup)
report.AppendLine(result.ToString());
}
else
report.AppendLine("None");
}
]]>
</code>
</script>
</project>