Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,6 @@ jobs:
if: failure()
uses: actions/upload-artifact@v4
with:
name: logStd
path: ./src/NodeDev.Blazor.Server/logs_std.txt
retention-days: 7

- name: Upload err Artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: logErr
path: ./src/NodeDev.Blazor.Server/logs_err.txt
name: logServer
path: ./src/NodeDev.Blazor.Server/logs
retention-days: 7
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,4 @@
/src/NodeDev.Core.Types/bin
/src/NodeDev.EndToEndTests/bin/Debug/net8.0
/src/NodeDev.EndToEndTests/obj
/src/NodeDev.Blazor.Server/project_backup.json
/src/NodeDev.Blazor.Server/logs_err.txt
/src/NodeDev.Blazor.Server/logs_std.txt
/src/NodeDev.Blazor.Server/project_backup.json
53 changes: 32 additions & 21 deletions src/NodeDev.EndToEndTests/Hooks/Hooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,31 @@

namespace NodeDev.EndToEndTests.Hooks;

#pragma warning disable CS0162 // Unreachable code detected. Some code is unreachable because it's used for optional logging purposes.

[Binding]
public class Hooks
{
public IPage User { get; private set; } = null!; //-> We'll call this property in the tests

private static Process App = null!;
private static StreamWriter StdOutput = null!;
private static StreamWriter StdError = null!;
private static StreamWriter? StdOutput;
private static StreamWriter? StdError;

private const int Port = 5166;
private const bool EnableLoggingOfServerOutput = false;

[BeforeFeature]
public static async Task StartServer()
{
StdOutput = new StreamWriter(File.Open("../../../../NodeDev.Blazor.Server/logs_std.txt", FileMode.Create));
StdError = new StreamWriter(File.Open("../../../../NodeDev.Blazor.Server/logs_err.txt", FileMode.Create));
if (EnableLoggingOfServerOutput)
{
var path = "../../../../NodeDev.Blazor.Server/logs";
Directory.CreateDirectory(path);

StdOutput = new StreamWriter(File.Open(Path.Combine(path, "logs_std.txt"), FileMode.Create));
StdError = new StreamWriter(File.Open(Path.Combine(path, "logs_err.txt"), FileMode.Create));
}

// start the server using either a environment variable set by the CI, or a default path.
// The default path will work if you're running the tests from Visual Studio.
Expand All @@ -30,37 +39,41 @@ public static async Task StartServer()
Arguments = $"run --no-build -- --urls http://localhost:{Port}",
WorkingDirectory = "../../../../NodeDev.Blazor.Server",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
RedirectStandardOutput = EnableLoggingOfServerOutput,
RedirectStandardError = EnableLoggingOfServerOutput
};

App.OutputDataReceived += App_OutputDataReceived;
App.ErrorDataReceived += App_ErrorDataReceived;

App.Start();
App.BeginOutputReadLine();
App.BeginErrorReadLine();

if (EnableLoggingOfServerOutput)
{
App.BeginOutputReadLine();
App.BeginErrorReadLine();
}

await Task.Delay(1000);

if(App.HasExited)
{
StdOutput.Flush();
StdError.Flush();
StdOutput?.Flush();
StdError?.Flush();
throw new Exception("Failed to start the server: " + App.ExitCode);
}
}

private static void App_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
if (e.Data != null)
StdError.WriteLine(e.Data);
StdError?.WriteLine(e.Data);
}

private static void App_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
if(e.Data != null)
StdOutput.WriteLine(e.Data);
StdOutput?.WriteLine(e.Data);
}

[BeforeScenario] // -> Notice how we're doing these steps before each scenario
Expand Down Expand Up @@ -89,11 +102,7 @@ public async Task RegisterSingleInstancePractitioner()
catch
{
if (i == 60)
{
StdOutput.Flush();
StdError.Flush();
throw;
}
}

await Task.Delay(1000);
Expand All @@ -110,11 +119,13 @@ public static async Task StopServer()
await Task.Delay(100);
}

if (StdOutput != null && StdError != null)
{
StdOutput.Flush();
StdError.Flush();

StdOutput.Flush();
StdError.Flush();

StdError.Dispose();
StdError.Dispose();
StdError.Dispose();
StdError.Dispose();
}
}
}