Skip to content

Commit 99fc8e4

Browse files
committed
Replaced Global Mutex file with file based locking which works xplat.
1 parent 7a1db73 commit 99fc8e4

File tree

11 files changed

+410
-229
lines changed

11 files changed

+410
-229
lines changed

src/Exceptionless.Signed/project.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@
109109
"System.Reflection.Emit.ILGeneration": "4.0.1",
110110
"System.Reflection.Emit.Lightweight": "4.0.1",
111111
"System.Runtime.Serialization.Primitives": "4.1.1",
112-
"System.Security.AccessControl": "4.0.0",
113-
"System.Threading.AccessControl": "4.0.0",
114112
"System.Threading.Thread": "4.0.0",
115113
"System.Xml.XmlDocument": "4.0.1",
116114
"System.Xml.XmlSerializer": "4.0.11"
@@ -137,13 +135,10 @@
137135
"System.Diagnostics.StackTrace": "4.0.1",
138136
"System.Diagnostics.TraceSource": "4.0.0",
139137
"System.Dynamic.Runtime": "4.0.11",
140-
"System.IO.IsolatedStorage": "4.0.1",
141138
"System.Net.NameResolution": "4.0.0",
142139
"System.Reflection.Emit.ILGeneration": "4.0.1",
143140
"System.Reflection.Emit.Lightweight": "4.0.1",
144141
"System.Runtime.Serialization.Primitives": "4.1.1",
145-
"System.Security.AccessControl": "4.0.0",
146-
"System.Threading.AccessControl": "4.0.0",
147142
"System.Threading.Thread": "4.0.0",
148143
"System.Xml.XmlDocument": "4.0.1",
149144
"System.Xml.XmlSerializer": "4.0.11"
@@ -170,13 +165,10 @@
170165
"System.Diagnostics.StackTrace": "4.0.1",
171166
"System.Diagnostics.TraceSource": "4.0.0",
172167
"System.Dynamic.Runtime": "4.0.11",
173-
"System.IO.IsolatedStorage": "4.0.1",
174168
"System.Net.NameResolution": "4.0.0",
175169
"System.Reflection.Emit.ILGeneration": "4.0.1",
176170
"System.Reflection.Emit.Lightweight": "4.0.1",
177171
"System.Runtime.Serialization.Primitives": "4.1.1",
178-
"System.Security.AccessControl": "4.0.0",
179-
"System.Threading.AccessControl": "4.0.0",
180172
"System.Threading.Thread": "4.0.0",
181173
"System.Xml.XmlDocument": "4.0.1",
182174
"System.Xml.XmlSerializer": "4.0.11"
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using Exceptionless.Logging;
5+
using Xunit;
6+
7+
namespace Exceptionless.Tests.Log {
8+
public abstract class FileExceptionlessLogTestBase {
9+
protected const string LOG_FILE = "test.log";
10+
11+
public virtual void CanWriteToLogFile() {
12+
DeleteLog();
13+
14+
using (FileExceptionlessLog log = GetLog(LOG_FILE)) {
15+
log.Info("Test");
16+
log.Flush();
17+
18+
Assert.True(LogExists());
19+
string contents = log.GetFileContents();
20+
21+
Assert.Equal("Test\r\n", contents);
22+
}
23+
}
24+
25+
public virtual void LogFlushTimerWorks() {
26+
DeleteLog();
27+
28+
using (FileExceptionlessLog log = GetLog(LOG_FILE)) {
29+
log.Info("Test");
30+
31+
string contents = log.GetFileContents();
32+
Assert.Equal("", contents);
33+
34+
Thread.Sleep(1010 * 3);
35+
36+
Assert.True(LogExists());
37+
contents = log.GetFileContents();
38+
39+
Assert.Equal("Test\r\n", contents);
40+
}
41+
}
42+
43+
public virtual void LogResetsAfter5mb() {
44+
DeleteLog();
45+
46+
using (FileExceptionlessLog log = GetLog(LOG_FILE)) {
47+
// write 3mb of content to the log
48+
for (int i = 0; i < 1024 * 3; i++)
49+
log.Info(new string('0', 1024));
50+
51+
log.Flush();
52+
Assert.True(log.GetFileSize() > 1024 * 1024 * 3);
53+
54+
// force a check file size call
55+
log.CheckFileSize();
56+
57+
// make sure it didn't clear the log
58+
Assert.True(log.GetFileSize() > 1024 * 1024 * 3);
59+
60+
// write another 3mb of content to the log
61+
for (int i = 0; i < 1024 * 3; i++)
62+
log.Info(new string('0', 1024));
63+
64+
log.Flush();
65+
// force a check file size call
66+
log.CheckFileSize();
67+
68+
// make sure it cleared the log
69+
long size = log.GetFileSize();
70+
71+
// should be 99 lines of text in the file
72+
Assert.True(size > 1024 * 99);
73+
}
74+
}
75+
76+
public virtual void CheckSizeDoesNotFailIfLogIsMissing() {
77+
using (FileExceptionlessLog log = GetLog(LOG_FILE + ".doesnotexist")) {
78+
log.CheckFileSize();
79+
}
80+
}
81+
82+
public virtual void LogIsThreadSafe() {
83+
DeleteLog();
84+
85+
using (FileExceptionlessLog log = GetLog(LOG_FILE)) {
86+
// write 3mb of content to the log in multiple threads
87+
Parallel.For(0, 1024 * 3, i => log.Info(new string('0', 1024)));
88+
89+
log.Flush();
90+
Assert.True(log.GetFileSize() > 1024 * 1024 * 3);
91+
92+
// force a check file size call
93+
log.CheckFileSize();
94+
95+
// make sure it didn't clear the log
96+
Assert.True(log.GetFileSize() > 1024 * 1024 * 3);
97+
98+
// write another 3mb of content to the log
99+
Parallel.For(0, 1024 * 3, i => log.Info(new string('0', 1024)));
100+
log.Flush();
101+
102+
long size = log.GetFileSize();
103+
Console.WriteLine("File: " + size);
104+
105+
// do the check size while writing to the log from multiple threads
106+
Parallel.Invoke(() => Parallel.For(0, 1024 * 3, i => log.Info(new string('0', 1024))), () => {
107+
Thread.Sleep(10);
108+
log.CheckFileSize();
109+
});
110+
111+
// should be more than 99 lines of text in the file
112+
size = log.GetFileSize();
113+
Console.WriteLine("File: " + size);
114+
Assert.True(size > 1024 * 99);
115+
}
116+
}
117+
118+
protected abstract FileExceptionlessLog GetLog(string filePath);
119+
120+
protected abstract bool LogExists(string path = LOG_FILE);
121+
122+
protected abstract void DeleteLog(string path = LOG_FILE);
123+
}
124+
}
Lines changed: 14 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,146 +1,46 @@
11
using System;
22
using System.IO;
3-
using System.Threading;
4-
using System.Threading.Tasks;
53
using Exceptionless.Logging;
64
using Xunit;
75

86
namespace Exceptionless.Tests.Log {
9-
public class FileExceptionlessLogTests : IDisposable {
10-
protected const string LOG_FILE = "test.log";
11-
7+
public class FileExceptionlessLogTests : FileExceptionlessLogTestBase {
128
[Fact]
13-
public void CanWriteToLogFile() {
14-
DeleteLog();
15-
16-
FileExceptionlessLog log = GetLog(LOG_FILE);
17-
log.Info("Test");
18-
log.Flush();
19-
20-
Assert.True(LogExists());
21-
string contents = log.GetFileContents();
22-
23-
Assert.Equal("Test\r\n", contents);
24-
25-
log.Dispose();
9+
public override void CanWriteToLogFile() {
10+
base.CanWriteToLogFile();
2611
}
2712

2813
[Fact]
29-
public void LogFlushTimerWorks() {
30-
DeleteLog();
31-
32-
FileExceptionlessLog log = GetLog(LOG_FILE);
33-
log.Info("Test");
34-
35-
string contents = log.GetFileContents();
36-
Assert.Equal("", contents);
37-
38-
Thread.Sleep(1010 * 3);
39-
40-
Assert.True(LogExists());
41-
contents = log.GetFileContents();
42-
43-
Assert.Equal("Test\r\n", contents);
44-
45-
log.Dispose();
14+
public override void CheckSizeDoesNotFailIfLogIsMissing() {
15+
base.CheckSizeDoesNotFailIfLogIsMissing();
4616
}
4717

4818
[Fact]
49-
public void LogResetsAfter5mb() {
50-
DeleteLog();
51-
52-
FileExceptionlessLog log = GetLog(LOG_FILE);
53-
54-
// write 3mb of content to the log
55-
for (int i = 0; i < 1024 * 3; i++)
56-
log.Info(new string('0', 1024));
57-
58-
log.Flush();
59-
Assert.True(log.GetFileSize() > 1024 * 1024 * 3);
60-
61-
// force a check file size call
62-
log.CheckFileSize();
63-
64-
// make sure it didn't clear the log
65-
Assert.True(log.GetFileSize() > 1024 * 1024 * 3);
66-
67-
// write another 3mb of content to the log
68-
for (int i = 0; i < 1024 * 3; i++)
69-
log.Info(new string('0', 1024));
70-
71-
log.Flush();
72-
// force a check file size call
73-
log.CheckFileSize();
74-
75-
// make sure it cleared the log
76-
long size = log.GetFileSize();
77-
78-
// should be 99 lines of text in the file
79-
Assert.True(size > 1024 * 99);
80-
81-
log.Dispose();
19+
public override void LogFlushTimerWorks() {
20+
base.LogFlushTimerWorks();
8221
}
8322

8423
[Fact]
85-
public void CheckSizeDoesNotFailIfLogIsMissing() {
86-
FileExceptionlessLog log = GetLog(LOG_FILE + ".doesnotexist");
87-
log.CheckFileSize();
24+
public override void LogIsThreadSafe() {
25+
base.LogIsThreadSafe();
8826
}
8927

9028
[Fact]
91-
public void LogIsThreadSafe() {
92-
DeleteLog();
93-
94-
FileExceptionlessLog log = GetLog(LOG_FILE);
95-
96-
// write 3mb of content to the log in multiple threads
97-
Parallel.For(0, 1024 * 3, i => log.Info(new string('0', 1024)));
98-
99-
log.Flush();
100-
Assert.True(log.GetFileSize() > 1024 * 1024 * 3);
101-
102-
// force a check file size call
103-
log.CheckFileSize();
104-
105-
// make sure it didn't clear the log
106-
Assert.True(log.GetFileSize() > 1024 * 1024 * 3);
107-
108-
// write another 3mb of content to the log
109-
Parallel.For(0, 1024 * 3, i => log.Info(new string('0', 1024)));
110-
log.Flush();
111-
112-
long size = log.GetFileSize();
113-
Console.WriteLine("File: " + size);
114-
115-
// do the check size while writing to the log from multiple threads
116-
Parallel.Invoke(
117-
() => Parallel.For(0, 1024 * 3, i => log.Info(new string('0', 1024))),
118-
() => {
119-
Thread.Sleep(10);
120-
log.CheckFileSize();
121-
});
122-
123-
// should be more than 99 lines of text in the file
124-
size = log.GetFileSize();
125-
Console.WriteLine("File: " + size);
126-
Assert.True(size > 1024 * 99);
127-
128-
log.Dispose();
29+
public override void LogResetsAfter5mb() {
30+
base.LogResetsAfter5mb();
12931
}
13032

131-
protected virtual FileExceptionlessLog GetLog(string filePath) {
33+
protected override FileExceptionlessLog GetLog(string filePath) {
13234
return new FileExceptionlessLog(filePath);
13335
}
13436

135-
protected virtual bool LogExists(string path = LOG_FILE) {
37+
protected override bool LogExists(string path = LOG_FILE) {
13638
return File.Exists(path);
13739
}
13840

139-
protected virtual void DeleteLog(string path = LOG_FILE) {
41+
protected override void DeleteLog(string path = LOG_FILE) {
14042
if (LogExists(path))
14143
File.Delete(path);
14244
}
143-
144-
public virtual void Dispose() {}
14545
}
14646
}

src/Exceptionless.Tests/Log/IsolatedStorageFileExceptionlessLogTests.cs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
using Exceptionless.Logging;
44
using Exceptionless.Serializer;
55
using Exceptionless.Storage;
6+
using Xunit;
67

78
namespace Exceptionless.Tests.Log {
8-
public class IsolatedStorageFileExceptionlessLogTests : FileExceptionlessLogTests {
9+
public class IsolatedStorageFileExceptionlessLogTests : FileExceptionlessLogTestBase, IDisposable {
910
private readonly IsolatedStorageObjectStorage _storage;
1011

1112
public IsolatedStorageFileExceptionlessLogTests() {
@@ -15,6 +16,31 @@ public IsolatedStorageFileExceptionlessLogTests() {
1516
_storage = new IsolatedStorageObjectStorage(resolver);
1617
}
1718

19+
[Fact]
20+
public override void CanWriteToLogFile() {
21+
base.CanWriteToLogFile();
22+
}
23+
24+
[Fact]
25+
public override void CheckSizeDoesNotFailIfLogIsMissing() {
26+
base.CheckSizeDoesNotFailIfLogIsMissing();
27+
}
28+
29+
[Fact]
30+
public override void LogFlushTimerWorks() {
31+
base.LogFlushTimerWorks();
32+
}
33+
34+
[Fact]
35+
public override void LogIsThreadSafe() {
36+
base.LogIsThreadSafe();
37+
}
38+
39+
[Fact]
40+
public override void LogResetsAfter5mb() {
41+
base.LogResetsAfter5mb();
42+
}
43+
1844
protected override FileExceptionlessLog GetLog(string filePath) {
1945
return new IsolatedStorageFileExceptionlessLog(filePath);
2046
}
@@ -28,11 +54,8 @@ protected override void DeleteLog(string path = LOG_FILE) {
2854
_storage.DeleteObject(path);
2955
}
3056

31-
public override void Dispose() {
32-
base.Dispose();
33-
34-
if (_storage != null)
35-
_storage.Dispose();
57+
public void Dispose() {
58+
_storage?.Dispose();
3659
}
3760
}
3861
}

src/Exceptionless.Tests/Plugins/PluginTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class PluginTests {
2323
public PluginTests(ITestOutputHelper output) {
2424
_writer = new TestOutputWriter(output);
2525
}
26-
26+
2727
private ExceptionlessClient CreateClient() {
2828
return new ExceptionlessClient(c => {
2929
c.UseLogger(new XunitExceptionlessLog(_writer) { MinimumLogLevel = LogLevel.Trace });

0 commit comments

Comments
 (0)