Skip to content
This repository has been archived by the owner on Jun 8, 2019. It is now read-only.

Commit

Permalink
more concurrency tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jkowalski committed Jun 14, 2006
1 parent 7a2e346 commit 2eee6cf
Showing 1 changed file with 55 additions and 10 deletions.
65 changes: 55 additions & 10 deletions tests/NLog.UnitTests/Targets/ConcurrentFileTests.cs
Expand Up @@ -54,7 +54,7 @@ public class ConcurrentFileTargetTests : NLogTestBase
{
private Logger logger = LogManager.GetCurrentClassLogger();

private void ConfigureSharedFile()
private void ConfigureSharedFile(string mode)
{
FileTarget ft = new FileTarget();
ft.FileName = "${basedir}/file.txt";
Expand All @@ -63,22 +63,39 @@ private void ConfigureSharedFile()
ft.OpenFileCacheTimeout = 10;
ft.OpenFileCacheSize = 1;
ft.LineEnding = FileTarget.LineEndingMode.LF;
SimpleConfigurator.ConfigureForTargetLogging(ft, LogLevel.Debug);

switch (mode)
{
case "async":
SimpleConfigurator.ConfigureForTargetLogging(new AsyncTargetWrapper(ft, 100, AsyncTargetWrapperOverflowAction.Grow), LogLevel.Debug);
break;

case "buffered":
SimpleConfigurator.ConfigureForTargetLogging(new BufferingTargetWrapper(ft, 100), LogLevel.Debug);
break;

case "buffered_timed_flush":
SimpleConfigurator.ConfigureForTargetLogging(new BufferingTargetWrapper(ft, 100, 10), LogLevel.Debug);
break;

default:
SimpleConfigurator.ConfigureForTargetLogging(ft, LogLevel.Debug);
break;
}
}

public void Process(string threadName, string numLogsString)
public void Process(string threadName, string numLogsString, string mode)
{
System.Threading.Thread.CurrentThread.Name = threadName;
ConfigureSharedFile();
ConfigureSharedFile(mode);
int numLogs = Convert.ToInt32(numLogsString);
for (int i = 0; i < numLogs; ++i)
{
logger.Debug("{0}", i);
}
}

[Test]
public void ConcurrentTest1()
private void DoConcurrentTest(int numProcesses, int numLogs, string mode)
{
string logFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "file.txt");

Expand All @@ -87,13 +104,11 @@ public void ConcurrentTest1()

StringBuilder expectedOutput = new StringBuilder();

int numProcesses = 3;
int numLogs = 100;
Process[] processes = new Process[numProcesses];

for (int i = 0; i < numProcesses; ++i)
{
processes[i] = SpawnMethod("Process", i.ToString(), numLogs.ToString());
processes[i] = SpawnMethod("Process", i.ToString(), numLogs.ToString(), mode);
}
for (int i = 0; i < numProcesses; ++i)
{
Expand All @@ -118,7 +133,37 @@ public void ConcurrentTest1()
maxNumber[thread]++;
}
}
//AssertFileContents(logFile, expectedOutput.ToString(), Encoding.ASCII);
}

private void DoConcurrentTest(string mode)
{
DoConcurrentTest(2, 10000, mode);
DoConcurrentTest(5, 4000, mode);
DoConcurrentTest(10, 2000, mode);
}

[Test]
public void SimpleConcurrentTest()
{
DoConcurrentTest("");
}

[Test]
public void AsyncConcurrentTest()
{
DoConcurrentTest(2, 100, "async");
}

[Test]
public void BufferedConcurrentTest()
{
DoConcurrentTest(2, 100, "buffered");
}

[Test]
public void BufferedTimedFlushConcurrentTest()
{
DoConcurrentTest(2, 100, "buffered_timed_flush");
}
}
}

0 comments on commit 2eee6cf

Please sign in to comment.