/
LogStreamManagerTests.cs
147 lines (131 loc) · 6.33 KB
/
LogStreamManagerTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System;
using System.Collections.Generic;
using System.Net;
using Kudu.FunctionalTests.Infrastructure;
using Kudu.TestHarness;
using Kudu.TestHarness.Xunit;
using Xunit;
namespace Kudu.FunctionalTests
{
[KuduXunitTestClass]
public class LogStreamManagerTests
{
[Fact]
public void TestLogStreamBasic()
{
string appName = "TestLogStreamBasic";
ApplicationManager.Run(appName, appManager =>
{
// Act
using (var localRepo = Git.Clone("LogTester"))
{
appManager.GitDeploy(localRepo.PhysicalPath);
}
CreateLogDirectory(appManager.SiteUrl, @"LogFiles\TestLogStreamBasic");
using (var waitHandle = new LogStreamWaitHandle(appManager.CreateLogStreamManager("TestLogStreamBasic").GetStream().Result))
{
string line = waitHandle.WaitNextLine(10000);
Assert.True(!String.IsNullOrEmpty(line) && line.Contains("Welcome"), "check welcome message: " + line);
string content = Guid.NewGuid().ToString();
WriteLogText(appManager.SiteUrl, @"LogFiles\TestLogStreamBasic\temp.txt", content);
line = waitHandle.WaitNextLine(10000);
Assert.Equal(content, line);
content = Guid.NewGuid().ToString();
WriteLogText(appManager.SiteUrl, @"LogFiles\TestLogStreamBasic\temp.log", content);
line = waitHandle.WaitNextLine(10000);
Assert.Equal(content, line);
// write to xml file, we should not get any live stream
content = Guid.NewGuid().ToString();
WriteLogText(appManager.SiteUrl, @"LogFiles\TestLogStreamBasic\temp.xml", content);
line = waitHandle.WaitNextLine(1000);
Assert.Null(line);
}
});
}
[Fact]
public void TestLogStreamSubFolder()
{
string appName = "TestLogStreamFilter";
ApplicationManager.Run(appName, appManager =>
{
// Act
using (var localRepo = Git.Clone("LogTester"))
{
appManager.GitDeploy(localRepo.PhysicalPath);
}
List<string> logFiles = new List<string>();
List<LogStreamWaitHandle> waitHandles = new List<LogStreamWaitHandle>();
for (int i = 0; i < 2; ++i)
{
logFiles.Add(@"LogFiles\TestLogStreamFilter\Folder" + i + "\\temp.txt");
//Create the directory
CreateLogDirectory(appManager.SiteUrl, @"LogFiles\TestLogStreamFilter\Folder" + i);
RemoteLogStreamManager mgr = appManager.CreateLogStreamManager("TestLogStreamFilter/folder" + i);
var waitHandle = new LogStreamWaitHandle(mgr.GetStream().Result);
string line = waitHandle.WaitNextLine(10000);
Assert.True(!string.IsNullOrEmpty(line) && line.Contains("Welcome"), "check welcome message: " + line);
waitHandles.Add(waitHandle);
}
using (LogStreamWaitHandle waitHandle = new LogStreamWaitHandle(appManager.CreateLogStreamManager("TestLogStreamFilter").GetStream().Result))
{
try
{
string line = waitHandle.WaitNextLine(10000);
Assert.True(!string.IsNullOrEmpty(line) && line.Contains("Welcome"), "check welcome message: " + line);
// write to folder0, we should not get any live stream for folder1 listener
string content = Guid.NewGuid().ToString();
WriteLogText(appManager.SiteUrl, logFiles[0], content);
line = waitHandle.WaitNextLine(10000);
Assert.Equal(content, line);
line = waitHandles[0].WaitNextLine(10000);
Assert.Equal(content, line);
line = waitHandles[1].WaitNextLine(1000);
Assert.True(line == null, "no more message: " + line);
// write to folder1, we should not get any live stream for folder0 listener
content = Guid.NewGuid().ToString();
WriteLogText(appManager.SiteUrl, logFiles[1], content);
line = waitHandle.WaitNextLine(10000);
Assert.Equal(content, line);
line = waitHandles[1].WaitNextLine(10000);
Assert.Equal(content, line);
line = waitHandles[0].WaitNextLine(1000);
Assert.True(line == null, "no more message: " + line);
}
finally
{
waitHandles[0].Dispose();
waitHandles[1].Dispose();
}
}
});
}
[Fact]
public void TestLogStreamNotFound()
{
string appName = "TestLogStreamNotFound";
ApplicationManager.Run(appName, appManager =>
{
RemoteLogStreamManager manager = new RemoteLogStreamManager(appManager.ServiceUrl + "/logstream/notfound");
using (var waitHandle = new LogStreamWaitHandle(manager.GetStream().Result))
{
string line = waitHandle.WaitNextLine(10000);
Assert.True(!String.IsNullOrEmpty(line) && line.Contains("Welcome"), "check welcome message: " + line);
}
});
}
private static void WriteLogText(string siteUrl, string filePath, string content)
{
string url = String.Format("{0}?path={1}&content={2}", siteUrl, filePath, content);
KuduAssert.VerifyUrl(url);
}
private static void CreateLogDirectory(string siteUrl, string directory)
{
if (!directory.EndsWith("\\"))
{
directory += "\\";
}
string url = String.Format("{0}?path={1}", siteUrl, directory);
KuduAssert.VerifyUrl(url);
}
}
}