Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for exceptions thrown during render with multiple worker processe…
…s. Keeps multiple processes from competing during renders.
- Loading branch information
1 parent
e3e52b3
commit 1019c0b
Showing
4 changed files
with
188 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading; | ||
using NUnit.Framework; | ||
using SquishIt.Framework; | ||
|
||
namespace SquishIt.Tests | ||
{ | ||
[TestFixture] | ||
public class MultipleWorkerProcessesTests | ||
{ | ||
[Test,Explicit] | ||
public void ExceptionIsThrowWhenMultipleWorkerThreadsAreWorking() | ||
{ | ||
int writingThreads = 4; | ||
int readingThreads = 20; | ||
int numberOfExecutions = 500; | ||
|
||
for (int i = 0; i < numberOfExecutions; i++) | ||
{ | ||
for (int y = 0; y < writingThreads; y++) | ||
{ | ||
Thread writingThread = new Thread(new ThreadStart(() => | ||
{ | ||
try | ||
{ | ||
System.Diagnostics.Debug.WriteLine("Writing CSS..."); | ||
Bundle.Css() | ||
.Add("1.css") | ||
.Add("2.css") | ||
.Add("3.css") | ||
.Add("4.css") | ||
.Add("5.css") | ||
.Add("6.css") | ||
.ForceRelease() | ||
.Render("combined_#.css"); | ||
} | ||
catch (Exception ex) | ||
{ | ||
System.Diagnostics.Debug.WriteLine(ex.Message); | ||
} | ||
})); | ||
|
||
writingThread.Start(); | ||
} | ||
|
||
for (int y = 0; y < readingThreads; y++) | ||
{ | ||
Thread readingThread = new Thread(new ThreadStart(() => | ||
{ | ||
var files = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "combined*.css"); | ||
var ii = 0; | ||
while (ii < 1000) | ||
{ | ||
System.Diagnostics.Debug.WriteLine("Reading CSS..."); | ||
files.ToList().ForEach(x => File.ReadAllText(x)); | ||
Thread.Sleep(50); | ||
ii++; | ||
} | ||
})); | ||
|
||
readingThread.Start(); | ||
} | ||
} | ||
|
||
Thread.Sleep(20000); | ||
} | ||
|
||
/*public void ReadAllCssFiles(object state) | ||
{ | ||
var files = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "combined*.css"); | ||
var i = 0; | ||
while (i < 2000) | ||
{ | ||
System.Diagnostics.Debug.WriteLine("Reading CSS..."); | ||
files.ToList().ForEach(x => File.ReadAllText(x)); | ||
Thread.Sleep(50); | ||
i++; | ||
} | ||
}*/ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters