Skip to content

Commit 8ca03ab

Browse files
committed
Fixed an issue with WaitAll running on STA threads, Refactored so we only need one waithandle
1 parent 3255e7c commit 8ca03ab

File tree

14 files changed

+39
-43
lines changed

14 files changed

+39
-43
lines changed

build/scripts/Building.fsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ open Versioning
2424

2525
module Build =
2626

27-
type private GlobalJson = JsonProvider<"../../global.json">
27+
type private GlobalJson = JsonProvider<"../../global.json", InferTypesFromValues = false>
2828
let private pinnedSdkVersion = GlobalJson.GetSample().Sdk.Version
2929

3030
let private compileCore () =

build/scripts/Targets.fsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Target "InternalizeDependencies" Build.ILRepack
3636

3737
Target "ChangeVersion" <| fun _ ->
3838
let newVersion = getBuildParam "version"
39-
Versioning.writeVersionIntoGlobalJson Commandline.project newVersion
39+
Versioning.writeVersionIntoVersionsJson Commandline.project newVersion
4040

4141
Target "Version" <| fun _ ->
4242
for v in Versioning.AllProjectVersions do

build/scripts/Versioning.fsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ open SemVerHelper
2424
open Commandline
2525

2626
module Versioning =
27-
type private GlobalJson = JsonProvider<"../../global.json">
28-
let globalJson = GlobalJson.Load("../../global.json");
27+
type private VersionsJson = JsonProvider<"../../versions.json">
28+
let globalJson = VersionsJson.Load("../../versions.json");
2929
let private versionOf project =
3030
match project with
3131
| Proc -> globalJson.Versions.Proc.Remove(0, 1)
@@ -34,16 +34,16 @@ module Versioning =
3434

3535
let private assemblyFileVersionOf v = sprintf "%i.%i.%i.0" v.Major v.Minor v.Patch |> parse
3636

37-
let writeVersionIntoGlobalJson project version =
37+
let writeVersionIntoVersionsJson project version =
3838
//write it with a leading v in the json, needed for the json type provider to keep things strings
3939
let pre (v: string) = match (v.StartsWith("v")) with | true -> v | _ -> sprintf "v%s" v
4040
let observableProcessVersion = pre version
41-
let versionsNode = GlobalJson.Versions(observableProcessVersion)
41+
let versionsNode = VersionsJson.Versions(observableProcessVersion)
4242

43-
let newGlobalJson = GlobalJson.Root (GlobalJson.Sdk(globalJson.Sdk.Version), versionsNode)
44-
use tw = new StreamWriter("global.json")
45-
newGlobalJson.JsonValue.WriteTo(tw, JsonSaveOptions.None)
46-
traceImportant <| sprintf "Written (%O) to global.json as the current version will use this version from now on as current in the build" version
43+
let newVersionsJson = VersionsJson.Root (versionsNode)
44+
use tw = new StreamWriter("versions.json")
45+
newVersionsJson.JsonValue.WriteTo(tw, JsonSaveOptions.None)
46+
traceImportant <| sprintf "Written (%O) to versions.json as the current version will use this version from now on as current in the build" version
4747

4848
type AssemblyVersionInfo = { Informational: SemVerInfo; Assembly: SemVerInfo; AssemblyFile: SemVerInfo; Project: ProjectInfo }
4949
let VersionInfo project =
@@ -53,15 +53,15 @@ module Versioning =
5353
match (Commandline.project) with
5454
| p when p = project -> if (isNullOrEmpty bv) then None else Some(parse(bv))
5555
| _ -> Some(parse(versionOf project))
56-
let target =getBuildParam "target"
56+
let target = getBuildParam "target"
5757
let isCurrentProject = project = Commandline.project
5858
match (target, buildVersion, isCurrentProject) with
5959
| ("release", None, _) -> failwithf "can not run release because no explicit version number was passed on the command line"
6060
| ("release", Some v, true) ->
6161
if (currentVersion >= v) then failwithf "tried to create release %O for project %O but current version is already at %O" v project currentVersion
6262
{ Informational= v; Assembly= assemblyVersionOf v; AssemblyFile = assemblyFileVersionOf v; Project = infoOf project }
6363
| _ ->
64-
tracefn "Not running 'release' target or %O is not the release current release target (%O) so using version in global.json (%O) as current" project (Commandline.project) currentVersion
64+
tracefn "Not running 'release' target or %O is not the release current release target (%O) so using version in versions.json (%O) as current" project (Commandline.project) currentVersion
6565
{ Informational= currentVersion; Assembly= assemblyVersionOf currentVersion; AssemblyFile = assemblyFileVersionOf currentVersion; Project = infoOf project}
6666

6767
let AllProjectVersions = Project.All |> Seq.map VersionInfo

global.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
{
22
"sdk": {
33
"version": "2.1.300"
4-
},
5-
"versions": {
6-
"proc": "v0.3.6"
74
}
85
}

src/Proc.Tests/LineOutputTests.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,15 @@ Windows IP Configuration
5858
Media State . . . . . . . . . . . : Media disconnected
5959
Connection-specific DNS Suffix . :";
6060

61-
private readonly string[] _expectedLines = _expected.Split(new [] {Environment.NewLine}, StringSplitOptions.None);
61+
private readonly string[] _expectedLines = _expected.Replace("\r\n", "\n").Split(new [] {"\n"}, StringSplitOptions.None);
6262

6363
[Fact]
6464
public void ProcSeesAllLines()
6565
{
6666
var args = TestCaseArguments("MoreText");
6767
var result = Proc.Start(args, WaitTimeout);
68+
result.ExitCode.Should().HaveValue();
69+
result.Completed.Should().BeTrue();
6870
result.ConsoleOut.Should().NotBeEmpty().And.HaveCount(_expectedLines.Length);
6971
for (var i = 0; i < result.ConsoleOut.Count; i++)
7072
result.ConsoleOut[i].Line.Should().Be(_expectedLines[i], i.ToString());
@@ -88,6 +90,8 @@ public void ConsoleWriterSeesAllLines()
8890
var writer = new TestConsoleOutWriter();
8991
var args = TestCaseArguments("MoreText");
9092
var result = Proc.Start(args, WaitTimeout, writer);
93+
result.ExitCode.Should().HaveValue();
94+
result.Completed.Should().BeTrue();
9195
var lines = writer.Lines;
9296
lines.Should().NotBeEmpty().And.HaveCount(_expectedLines.Length + 1);
9397
for (var i = 0; i < lines.Length - 1; i++)
@@ -97,7 +101,7 @@ public void ConsoleWriterSeesAllLines()
97101
public class TestConsoleOutWriter : IConsoleOutWriter
98102
{
99103
private readonly StringBuilder _sb = new StringBuilder();
100-
public string[] Lines => _sb.ToString().Split(new [] {Environment.NewLine}, StringSplitOptions.None);
104+
public string[] Lines => _sb.ToString().Replace("\r\n", "\n").Split(new [] {"\n"}, StringSplitOptions.None);
101105
public string Text => _sb.ToString();
102106

103107
public void Write(Exception e) => throw e;

src/Proc.Tests/Proc.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>netcoreapp1.1</TargetFramework>
3+
<TargetFramework>netcoreapp2.1</TargetFramework>
44
<AssemblyName>Proc.Tests</AssemblyName>
55
<RootNamespace>ProcNet.Tests</RootNamespace>
66
</PropertyGroup>

src/Proc.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ ProjectSection(SolutionItems) = preProject
88
..\paket.dependencies = ..\paket.dependencies
99
..\global.json = ..\global.json
1010
..\build\Versioning.targets = ..\build\Versioning.targets
11-
..\build\outputpath.props = ..\build\outputpath.props
1211
..\.editorconfig = ..\.editorconfig
1312
..\.gitignore = ..\.gitignore
1413
..\build.bat = ..\build.bat
1514
..\build.sh = ..\build.sh
1615
..\readme.md = ..\readme.md
17-
..\nuget.config = ..\nuget.config
16+
..\versions.json = ..\versions.json
17+
outputpath.props = outputpath.props
1818
EndProjectSection
1919
EndProject
2020
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Proc.Tests.Binary", "Proc.Tests.Binary\Proc.Tests.Binary.csproj", "{D3AFFBE0-8F40-42C7-8A6A-BCCD2EDF4A3E}"

src/Proc/BufferedObservableProcess.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ public void StartAsyncReads()
139139
this.Process.StandardOutput.BaseStream.Flush();
140140
this.Process.StandardError.BaseStream.Flush();
141141

142-
this._stdOutSubscription = this.Process.ObserveStandardOutBuffered(_observer, BufferSize, ContinueReadingFromProcessReaders, _ctx.Token);
143-
this._stdErrSubscription = this.Process.ObserveErrorOutBuffered(_observer, BufferSize, ContinueReadingFromProcessReaders, _ctx.Token);
142+
this._stdOutSubscription = this.Process.ObserveStandardOutBuffered(_observer, BufferSize, () => this.ContinueReadingFromProcessReaders(), _ctx.Token);
143+
this._stdErrSubscription = this.Process.ObserveErrorOutBuffered(_observer, BufferSize, () => this.ContinueReadingFromProcessReaders(), _ctx.Token);
144144
this._reading = true;
145145
}
146146
}
0 Bytes
Binary file not shown.

src/Proc/ObservableProcess.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,6 @@ protected override IObservable<CharactersOut> CreateConsoleOutObservable()
5757

5858
private static readonly char[] NewlineChars = Environment.NewLine.ToCharArray();
5959

60-
private readonly ManualResetEvent _subscribeWaitHandle = new ManualResetEvent(false);
61-
private bool _waitLines;
62-
protected override WaitHandle[] CompletionHandles()
63-
{
64-
if (!_waitLines) return base.CompletionHandles();
65-
var waitHandles = base.CompletionHandles();
66-
return new List<WaitHandle>(waitHandles) { this._subscribeWaitHandle }.ToArray();
67-
}
68-
6960
/// <summary>
7061
/// Subclasses can implement this and return true to stop buffering lines.
7162
/// This is great for long running processes to only buffer console output until
@@ -92,7 +83,6 @@ protected virtual bool BufferBoundary(char[] stdOut, char[] stdErr)
9283

9384
public IDisposable Subscribe(IObserver<LineOut> observer)
9485
{
95-
this._waitLines = true;
9686
var published = this.OutStream.Publish();
9787
var boundaries = published
9888
.Where(o => o.EndsWithNewLine || o.StartsWithCarriage || this.BufferBoundary(_bufferStdOutRemainder, _bufferStdErrRemainder));
@@ -111,12 +101,12 @@ public IDisposable Subscribe(IObserver<LineOut> observer)
111101
e =>
112102
{
113103
observer.OnError(e);
114-
_subscribeWaitHandle.Set();
104+
SetCompletedHandle();
115105
},
116106
() =>
117107
{
118108
observer.OnCompleted();
119-
_subscribeWaitHandle.Set();
109+
SetCompletedHandle();
120110
});
121111
var connected = published.Connect();
122112
return new CompositeDisposable(newlines, connected);

0 commit comments

Comments
 (0)