Skip to content
This repository was archived by the owner on Jul 18, 2024. It is now read-only.

Commit b3dd266

Browse files
NikolayPianikovNikolayPianikov
NikolayPianikov
authored and
NikolayPianikov
committed
Fix tests on TeamCity
1 parent 53e7f29 commit b3dd266

24 files changed

+88
-21
lines changed

.teamcity/settings.kts

-4
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,13 @@ object BuildAndTestBuildType: BuildType({
4444
dotnetTest {
4545
name = "Run tests"
4646
sdk = Settings.dotnetToolVersion
47-
dockerImage = Settings.dockerImageSdk
48-
dockerImagePlatform = DotnetTestStep.ImagePlatform.Linux
4947
}
5048

5149
dotnetPack {
5250
name = "Pack"
5351
sdk = Settings.dotnetToolVersion
5452
executionMode = BuildStep.ExecutionMode.RUN_ON_SUCCESS
5553
configuration = "Release"
56-
dockerImage = Settings.dockerImageSdk
57-
dockerImagePlatform = DotnetPackStep.ImagePlatform.Linux
5854
}
5955
}
6056

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
using Xunit;
2+
3+
[assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly, DisableTestParallelization = true, MaxParallelThreads = 1)]

TeamCity.CSharpInteractive.Tests/Integration/CSharpScriptRunnerTests.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace TeamCity.CSharpInteractive.Tests.Integration
1010
using Shouldly;
1111
using Xunit;
1212

13+
[CollectionDefinition("Integration", DisableParallelization = true)]
1314
public class CSharpScriptRunnerTests
1415
{
1516
private readonly Mock<ILog<CSharpScriptRunner>> _log;
@@ -54,7 +55,7 @@ public void ShouldRunValidCode(string script)
5455
new object[] {"class Abc" + Environment.NewLine + "{}"},
5556
// using System;
5657
new object[] {"Console.WriteLine(10);"}
57-
};
58+
};
5859

5960
[Fact]
6061
public void ShouldPreserveState()

TeamCity.CSharpInteractive.Tests/Integration/CommandLineTests.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace TeamCity.CSharpInteractive.Tests.Integration
1313
using Xunit;
1414
using Composer = Composer;
1515

16+
[CollectionDefinition("Integration", DisableParallelization = true)]
1617
public class CommandLineTests
1718
{
1819
[Fact]
@@ -28,7 +29,7 @@ public void ShouldRun()
2829
exitCode.HasValue.ShouldBeTrue();
2930
exitCode.ShouldBe(0);
3031
events.Any(i => i.IsError).ShouldBeFalse();
31-
events.Any(i => !i.IsError && i.Line == "Hello").ShouldBeTrue();
32+
events.Any(i => !i.IsError && i.Line.Contains("Hello")).ShouldBeTrue();
3233
}
3334

3435
[Fact]
@@ -46,7 +47,7 @@ public void ShouldRunWithEnvironmentVariable()
4647
exitCode.HasValue.ShouldBeTrue();
4748
exitCode.ShouldBe(0);
4849
events.Any(i => i.IsError).ShouldBeFalse();
49-
events.Any(i => !i.IsError && i.Line == "VAL=123").ShouldBeTrue();
50+
events.Any(i => !i.IsError && i.Line.Contains("VAL=123")).ShouldBeTrue();
5051
}
5152

5253
[Fact]
@@ -82,7 +83,7 @@ public async Task ShouldRunAsync()
8283
exitCode.HasValue.ShouldBeTrue();
8384
exitCode.ShouldBe(0);
8485
events.Any(i => i.IsError).ShouldBeFalse();
85-
events.Any(i => !i.IsError && i.Line == "Hello").ShouldBeTrue();
86+
events.Any(i => !i.IsError && i.Line.Contains("Hello")).ShouldBeTrue();
8687
}
8788

8889
[Fact]

TeamCity.CSharpInteractive.Tests/Integration/HelpTests.cs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace TeamCity.CSharpInteractive.Tests.Integration
66
using Shouldly;
77
using Xunit;
88

9+
[CollectionDefinition("Integration", DisableParallelization = true)]
910
public class HelpTests
1011
{
1112
[Theory]

TeamCity.CSharpInteractive.Tests/Integration/NuGetTests.cs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace TeamCity.CSharpInteractive.Tests.Integration
77
using Shouldly;
88
using Xunit;
99

10+
[CollectionDefinition("Integration", DisableParallelization = true)]
1011
public class NuGetTests
1112
{
1213
[Fact]

TeamCity.CSharpInteractive.Tests/Integration/ScriptRunTests.cs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace TeamCity.CSharpInteractive.Tests.Integration
88
using Shouldly;
99
using Xunit;
1010

11+
[CollectionDefinition("Integration", DisableParallelization = true)]
1112
public class ScriptRunTests
1213
{
1314
private const int InitialLinesCount = 3;

TeamCity.CSharpInteractive.Tests/Integration/TeamCityScriptRunTests.cs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace TeamCity.CSharpInteractive.Tests.Integration
44
using Shouldly;
55
using Xunit;
66

7+
[CollectionDefinition("Integration", DisableParallelization = true)]
78
public class ScriptRunTeamCityScriptRunTestsTests
89
{
910
private const int InitialMessagesCount = 3;

TeamCity.CSharpInteractive.Tests/Integration/TestTool.cs

+25-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace TeamCity.CSharpInteractive.Tests.Integration
33
using System;
44
using System.Collections.Generic;
55
using System.Linq;
6+
using System.Text;
67
using Contracts;
78
using Core;
89
using JetBrains.TeamCity.ServiceMessages;
@@ -36,7 +37,7 @@ public static IProcessResult Run(IEnumerable<string> args, IEnumerable<string> s
3637
Run(CreateScriptCommandLine(args, scriptArgs, vars, lines));
3738

3839
public static IProcessResult Run(params string[] lines) =>
39-
Run(DotNetScript.Create(lines));
40+
Run(DotNetScript.Create(lines).WithVars(("TEAMCITY_PROJECT_NAME", string.Empty), ("TEAMCITY_VERSION", string.Empty)));
4041

4142
public static IProcessResult RunUnderTeamCity(params string[] lines) =>
4243
Run(CreateScriptCommandLine(Array.Empty<string>(), Array.Empty<string>(), TeamCityVars, lines));
@@ -91,6 +92,29 @@ public ProcessResult(int exitCode, IReadOnlyList<CommandLineOutput> events)
9192
public IReadOnlyCollection<string> StdOut { get; }
9293

9394
public IReadOnlyCollection<string> StdErr { get; }
95+
96+
public override string ToString()
97+
{
98+
var sb = new StringBuilder();
99+
sb.AppendLine($"Exit code: {ExitCode}");
100+
sb.AppendLine();
101+
sb.AppendLine($"StdOut({StdOut.Count}):");
102+
foreach (var line in StdOut)
103+
{
104+
sb.Append(" ");
105+
sb.AppendLine(line);
106+
}
107+
108+
sb.AppendLine();
109+
sb.AppendLine($"StdErr({StdErr.Count}):");
110+
foreach (var line in StdErr)
111+
{
112+
sb.Append(" ");
113+
sb.AppendLine(line);
114+
}
115+
116+
return sb.ToString();
117+
}
94118
}
95119
}
96120
}

TeamCity.CSharpInteractive.Tests/UsageScenarios/CommandLineAsync.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// ReSharper disable StringLiteralTypo
2+
// ReSharper disable SuggestVarOrType_BuiltInTypes
23
namespace TeamCity.CSharpInteractive.Tests.UsageScenarios
34
{
45
using System;
@@ -9,10 +10,11 @@ namespace TeamCity.CSharpInteractive.Tests.UsageScenarios
910

1011
public class CommandLineAsync: Scenario
1112
{
12-
[SkippableFact(Timeout = 5000)]
13+
[SkippableFact]
1314
public async Task Run()
1415
{
1516
Skip.IfNot(Environment.OSVersion.Platform == PlatformID.Win32NT);
17+
Skip.IfNot(string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("TEAMCITY_VERSION")));
1618

1719
// $visible=true
1820
// $tag=2 Command Line API

TeamCity.CSharpInteractive.Tests/UsageScenarios/CommandLineAsyncCancellation.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ namespace TeamCity.CSharpInteractive.Tests.UsageScenarios
1010

1111
public class CommandLineAsyncCancellation: Scenario
1212
{
13-
[SkippableFact(Timeout = 5000)]
13+
[SkippableFact]
1414
public void Run()
1515
{
1616
Skip.IfNot(Environment.OSVersion.Platform == PlatformID.Win32NT);
17+
Skip.IfNot(string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("TEAMCITY_VERSION")));
1718

1819
// $visible=true
1920
// $tag=2 Command Line API

TeamCity.CSharpInteractive.Tests/UsageScenarios/CommandLineInParallel.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// ReSharper disable StringLiteralTypo
2+
// ReSharper disable SuggestVarOrType_BuiltInTypes
23
namespace TeamCity.CSharpInteractive.Tests.UsageScenarios
34
{
45
using System;
@@ -9,10 +10,11 @@ namespace TeamCity.CSharpInteractive.Tests.UsageScenarios
910

1011
public class CommandLineInParallel: Scenario
1112
{
12-
[SkippableFact(Timeout = 5000)]
13+
[SkippableFact]
1314
public void Run()
1415
{
1516
Skip.IfNot(Environment.OSVersion.Platform == PlatformID.Win32NT);
17+
Skip.IfNot(string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("TEAMCITY_VERSION")));
1618

1719
// $visible=true
1820
// $tag=2 Command Line API

TeamCity.CSharpInteractive.Tests/UsageScenarios/CommandLineOutput.cs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// ReSharper disable StringLiteralTypo
2+
// ReSharper disable SuggestVarOrType_BuiltInTypes
23
namespace TeamCity.CSharpInteractive.Tests.UsageScenarios
34
{
45
using System;
@@ -12,6 +13,7 @@ public class CommandLineOutput: Scenario
1213
public void Run()
1314
{
1415
Skip.IfNot(Environment.OSVersion.Platform == PlatformID.Win32NT);
16+
Skip.IfNot(string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("TEAMCITY_VERSION")));
1517

1618
// $visible=true
1719
// $tag=2 Command Line API

TeamCity.CSharpInteractive.Tests/UsageScenarios/CommandLineSimple.cs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// ReSharper disable StringLiteralTypo
2+
// ReSharper disable SuggestVarOrType_BuiltInTypes
23
namespace TeamCity.CSharpInteractive.Tests.UsageScenarios
34
{
45
using System;
@@ -12,6 +13,7 @@ public class CommandLineSimple: Scenario
1213
public void Run()
1314
{
1415
Skip.IfNot(Environment.OSVersion.Platform == PlatformID.Win32NT);
16+
Skip.IfNot(string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("TEAMCITY_VERSION")));
1517

1618
// $visible=true
1719
// $tag=2 Command Line API

TeamCity.CSharpInteractive.Tests/UsageScenarios/CommandLineWithTimeout.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
// ReSharper disable StringLiteralTypo
2+
// ReSharper disable SuggestVarOrType_BuiltInTypes
23
namespace TeamCity.CSharpInteractive.Tests.UsageScenarios
34
{
45
using System;
5-
using System.Threading;
66
using Contracts;
77
using Shouldly;
88
using Xunit;
99

1010
public class CommandLineWithTimeout: Scenario
1111
{
12-
[SkippableFact(Timeout = 5000)]
12+
[SkippableFact]
1313
public void Run()
1414
{
1515
Skip.IfNot(Environment.OSVersion.Platform == PlatformID.Win32NT);
16+
Skip.IfNot(string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("TEAMCITY_VERSION")));
1617

1718
// $visible=true
1819
// $tag=2 Command Line API

TeamCity.CSharpInteractive.Tests/UsageScenarios/NuGetRestore.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public void Run()
1616
// $priority=00
1717
// $description=Restore NuGet a package of newest version
1818
// {
19-
IEnumerable<NuGetPackage> packages = GetService<INuGet>().Restore("IoC.Container");
19+
IEnumerable<NuGetPackage> packages = GetService<INuGet>().Restore("IoC.Container", "*");
2020
// }
2121

2222
packages.ShouldNotBeEmpty();

TeamCity.CSharpInteractive.Tests/UsageScenarios/TeamCityServiceMessages.cs

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public class TeamCityServiceMessages: Scenario
1111
[SkippableFact]
1212
public void Run()
1313
{
14+
Skip.IfNot(string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("TEAMCITY_VERSION")));
15+
1416
// $visible=true
1517
// $tag=3 TeamCity Service Messages API
1618
// $priority=00

TeamCity.CSharpInteractive/Cleaner.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public Cleaner(ILog<Cleaner> log, IFileSystem fileSystem)
1616

1717
public IDisposable Track(string path)
1818
{
19-
_log.Trace($"Trace \"{path}\".");
19+
_log.Trace($"Start tracking \"{path}\".");
2020
return Disposable.Create(() =>
2121
{
2222
_log.Trace($"Delete \"{path}\".");

TeamCity.CSharpInteractive/Debugger.cs

+2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
namespace TeamCity.CSharpInteractive
22
{
33
using System;
4+
using System.Diagnostics.CodeAnalysis;
45
using System.Threading;
56

7+
[ExcludeFromCodeCoverage]
68
internal class Debugger: IActive
79
{
810
private readonly ILog<Debugger> _log;

TeamCity.CSharpInteractive/ExitManager.cs

+2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
namespace TeamCity.CSharpInteractive
33
{
44
using System;
5+
using System.Diagnostics.CodeAnalysis;
56
using System.Threading;
67

8+
[ExcludeFromCodeCoverage]
79
internal class ExitManager: IActive
810
{
911
private readonly ISettings _settings;

TeamCity.CSharpInteractive/Process.cs

+17-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ internal class Process: IProcess
1616
private readonly System.Diagnostics.Process _process;
1717
private CommandLine? _commandLine;
1818
private Text _processId;
19+
private int _disposed;
1920

2021
public Process(
2122
ILog<Process> log,
@@ -100,10 +101,22 @@ private void ProcessOutput(DataReceivedEventArgs e, CommandLine commandLine, boo
100101

101102
public void Dispose()
102103
{
103-
_process.Exited -= ProcessOnExited;
104-
_process.OutputDataReceived -= ProcessOnOutputDataReceived;
105-
_process.ErrorDataReceived -= ProcessOnErrorDataReceived;
106-
_process.Dispose();
104+
try
105+
{
106+
if (System.Threading.Interlocked.Exchange(ref _disposed, 1) != 0)
107+
{
108+
return;
109+
}
110+
111+
_process.Exited -= ProcessOnExited;
112+
_process.OutputDataReceived -= ProcessOnOutputDataReceived;
113+
_process.ErrorDataReceived -= ProcessOnErrorDataReceived;
114+
_process.Dispose();
115+
}
116+
catch (Exception exception)
117+
{
118+
_log.Trace($"Exception during disposing: {exception}.");
119+
}
107120
}
108121
}
109122
}

TeamCity.CSharpInteractive/ScriptOptionsFactory.cs

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public bool TryRegisterAssembly(string fileName, out string description)
5151
{
5252
try
5353
{
54+
fileName = Path.GetFullPath(fileName);
5455
_log.Trace($"Try register the assembly \"{fileName}\".");
5556
var reference = MetadataReference.CreateFromFile(fileName);
5657
description = reference.Display ?? string.Empty;

TeamCity.CSharpInteractive/UniqueNameGenerator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ namespace TeamCity.CSharpInteractive
77
[ExcludeFromCodeCoverage]
88
internal class UniqueNameGenerator : IUniqueNameGenerator
99
{
10-
public string Generate() => Guid.NewGuid().ToString().Replace("-", string.Empty);
10+
public string Generate() => Guid.NewGuid().ToString().Replace("-", string.Empty)[..8];
1111
}
1212
}

sdk.cmd

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
set SDKVersion=6.0
2+
set WorkingDirectory=wd
3+
4+
docker pull mcr.microsoft.com/dotnet/sdk:%SDKVersion%
5+
@for /f %%i in ('docker system info --format "{{.OSType}}"') do set OSType=%%i
6+
@SET DRIVE=/
7+
@IF [%OSType%]==[windows] SET DRIVE=C:/
8+
docker run -it --rm "-w=%DRIVE%%WorkingDirectory%" "--volume=%~dp0:%DRIVE%%WorkingDirectory%" mcr.microsoft.com/dotnet/sdk:%SDKVersion% %*

0 commit comments

Comments
 (0)