Skip to content

Commit

Permalink
TorLogger: prevent double initialization
Browse files Browse the repository at this point in the history
Co-authored-by: Afshin Arani <afshin@arani.dev>
  • Loading branch information
knocte and aarani committed Aug 2, 2023
1 parent 94d6ad9 commit f07dc78
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 26 deletions.
6 changes: 0 additions & 6 deletions NOnion.Tests/HiddenServicesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ namespace NOnion.Tests
{
public class HiddenServicesTests
{
[SetUp]
public void Init()
{
TorLogger.Init(TestContext.Progress.WriteLine);
}

/* It's possible that the router returned by GetRandomFallbackDirectory or
* GetRandomRoutersForDirectoryBrowsing be inaccessable so we need to continue
* retrying if an exceptions happened to make sure the issues are not related
Expand Down
17 changes: 17 additions & 0 deletions NOnion.Tests/LoggerSetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;

namespace NOnion.Tests
{
[SetUpFixture]
public class LoggerSetup
{
[OneTimeSetUp]
public void Init()
{
TorLogger.Init(TestContext.Progress.WriteLine);
}
}
}
6 changes: 0 additions & 6 deletions NOnion.Tests/MonohopCircuits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ namespace NOnion.Tests
{
public class MonohopCircuits
{
[SetUp]
public void Init()
{
TorLogger.Init(TestContext.Progress.WriteLine);
}

/* It's possible that the router returned by GetRandomFallbackDirectory or
* GetRandomRoutersForDirectoryBrowsing be inaccessable so we need to continue
* retrying if an exceptions happened to make sure the issues are not related
Expand Down
6 changes: 0 additions & 6 deletions NOnion.Tests/MultihopCircuits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ namespace NOnion.Tests
{
public class MultihopCircuits
{
[SetUp]
public void Init()
{
TorLogger.Init(TestContext.Progress.WriteLine);
}

/* It's possible that the router returned by GetRandomFallbackDirectory or
* GetRandomRoutersForDirectoryBrowsing be inaccessable so we need to continue
* retrying if an exceptions happened to make sure the issues are not related
Expand Down
6 changes: 0 additions & 6 deletions NOnion.Tests/OutsideWorldConnectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ namespace NOnion.Tests
{
internal class OutsideWorldConnectionTest
{
[SetUp]
public void Init()
{
TorLogger.Init(TestContext.Progress.WriteLine);
}

/* It's possible that the router returned by GetRandomFallbackDirectory or
* GetRandomRoutersForDirectoryBrowsing be inaccessable so we need to continue
* retrying if an exceptions happened to make sure the issues are not related
Expand Down
2 changes: 0 additions & 2 deletions NOnion.Tests/TorDirectoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public void Init()
)
);
cachePath.Create();

TorLogger.Init(TestContext.Progress.WriteLine);
}

private DirectoryInfo cachePath = null;
Expand Down
3 changes: 3 additions & 0 deletions NOnion/TorLogger.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ module TorLogger =
let mutable LoggerOpt: Option<Action<string>> = None

let Init(loggingFunc: Action<string>) =
if LoggerOpt.IsSome then
failwith "TorLogger.Init() called more than once"

LoggerOpt <- Some loggingFunc

let Log(msg: string) =
Expand Down

0 comments on commit f07dc78

Please sign in to comment.