public static void AssertFileExists(string file, bool delete) { int timeout = 100; while (timeout > 0) { try { if (File.Exists(file)) { if (delete) { TestTracer.WriteTraceInfo("Deleting file {0}...", file); File.Delete(file); } return; } } catch (Exception) { } timeout--; Thread.Sleep(100); } Assert.Fail("Expected file does not exist:" + file); }
public void TestLongSMTPDataSessionWithoutNewline() { long memoryUsage = Shared.GetCurrentMemoryUsage(); var socket = new TcpConnection(); socket.Connect(25); socket.Receive(); socket.Send("HELO test.com\r\n"); socket.Receive(); // Build a large string... var sb = new StringBuilder(); sb.Append("A01"); for (int i = 0; i < 10000; i++) { sb.Append("01234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890"); } socket.Send("MAIL FROM: [email protected]\r\n"); socket.Receive(); socket.Send("RCPT TO: [email protected]\r\n"); socket.Receive(); socket.Send("DATA\r\n"); socket.Receive(); for (int i = 1; i <= 1000; i++) { Shared.AssertLowMemoryUsage(memoryUsage + 30); try { socket.Send(sb.ToString()); } catch (Exception) { return; } if ((i % 10) == 0) { TestTracer.WriteTraceInfo("{0}/{1}", i, 1000); } } socket.Send("\r\n.\r\n"); string result = socket.Receive(); Assert.IsTrue(result.StartsWith("554 Too long line was received. Transmission aborted.")); socket.Send("QUIT\r\n"); socket.Receive(); socket.Disconnect(); }
public void SetupEnvWith50MillionMessages() { const int accountCount = 1; const int folderCount = 1; const int messageCount = 100000; var accounts = new List <string>(); for (int accountIdx = 0; accountIdx < accountCount; accountIdx++) { var account = string.Format("test-{0}@test.com", accountIdx); accounts.Add(account); TestTracer.WriteTraceInfo("Setting up {0}...", account); SingletonProvider <TestSetup> .Instance.AddAccount(_domain, account, "test"); } var folders = new List <string>(); for (int folderIdx = 0; folderIdx < folderCount; folderIdx++) { folders.Add(string.Format("Folder-{0}", folderIdx)); } var parallelOptions = new ParallelOptions(); parallelOptions.MaxDegreeOfParallelism = 10; var watch = new Stopwatch(); watch.Start(); Parallel.ForEach(accounts, parallelOptions, account => { TestTracer.WriteTraceInfo("Processing messages for {0}...", account); var sim = new ImapClientSimulator(); Assert.IsTrue(sim.ConnectAndLogon(account, "test")); foreach (var folder in folders) { Assert.IsTrue(sim.CreateFolder(folder)); for (int i = 0; i < messageCount; i++) { string f = sim.SendSingleCommandWithLiteral("A01 APPEND " + folder + " {1}", "A"); Assert.IsTrue(f.Contains("A01 OK APPEND completed"), f); } } sim.Disconnect(); }); watch.Stop(); TestTracer.WriteTraceInfo(watch.ElapsedMilliseconds.ToString()); }
public void TestSendToManyRecipients() { // Add distribution list hMailServer.Accounts accounts = _domain.Accounts; var recipients = new List <string>(); for (int i = 0; i < 1000; i++) { hMailServer.Account account = SingletonProvider <TestSetup> .Instance.AddAccount(accounts, string.Format("recipient{0}@test.com", i), "test"); recipients.Add(account.Address); Marshal.ReleaseComObject(account); if (i % 10 == 0) { TestTracer.WriteTraceInfo("Creating accounts: {0}/{1}", i, 1000); } } Marshal.ReleaseComObject(accounts); var sw = new Stopwatch(); sw.Start(); SmtpClientSimulator.StaticSend("*****@*****.**", recipients, "Test", "Test message"); sw.Stop(); Console.WriteLine("Elapsed time: " + sw.Elapsed.TotalSeconds); string dataDir = Path.Combine(SingletonProvider <TestSetup> .Instance.GetApp().Settings.Directories.DataDirectory, "test.com"); // Check number of accounts. RetryHelper.TryAction(() => { if (IsFolderCountReached(dataDir, 1000)) { return; } throw new Exception("Not enough files in folder yet."); }, TimeSpan.FromSeconds(5), TimeSpan.FromMinutes(2)); }
public void TestSendAttachments() { string dataDir = Path.Combine(SingletonProvider <TestSetup> .Instance.GetApp().Settings.Directories.DataDirectory, "test.com"); string accountDir = Path.Combine(dataDir, "test"); int memoryUsage = Shared.GetCurrentMemoryUsage(); int maxMemoryUsage = memoryUsage + 5; const int numberOfMessages = 1000; string executableName = Shared.GetExecutableName(); var mail = new MailMessage { From = new MailAddress("*****@*****.**") }; mail.To.Add("*****@*****.**"); mail.Subject = "Automatic test"; mail.Body = "Automatic test"; mail.BodyEncoding = Encoding.GetEncoding(1252); mail.SubjectEncoding = Encoding.GetEncoding(1252); mail.Attachments.Add(new Attachment(executableName)); for (int i = 1; i <= numberOfMessages; i++) { var oClient = new SmtpClient("127.0.0.1", 25); oClient.Send(mail); if (i % 10 == 0) { TestTracer.WriteTraceInfo("{0}/{1}", i, 1000); WaitForFilesInFolder(accountDir, i); Shared.AssertLowMemoryUsage(maxMemoryUsage); } } _domain.Delete(); }
public void TestSend200KMessages() { string dataDir = Path.Combine(SingletonProvider <TestSetup> .Instance.GetApp().Settings.Directories.DataDirectory, "test.com"); string accountDir = Path.Combine(dataDir, "test"); int memoryUsage = Shared.GetCurrentMemoryUsage(); int maxMemoryUsage = memoryUsage + 5; const int numberOfMessages = 200000; var stopwatch = Stopwatch.StartNew(); for (int i = 1; i <= numberOfMessages; i++) { SmtpClientSimulator.StaticSend("*****@*****.**", "*****@*****.**", "Test", "Test message"); if (i % 100 == 0) { double messagesPerSecond = 100 / stopwatch.Elapsed.TotalSeconds; Shared.AssertLowMemoryUsage(maxMemoryUsage); TestTracer.WriteTraceInfo("{0}/{1}. Messages per second: {2}", i, numberOfMessages, messagesPerSecond); stopwatch.Reset(); stopwatch.Start(); ; } } // Check number of delivered messages. RetryHelper.TryAction(() => { Shared.AssertLowMemoryUsage(maxMemoryUsage); int actualNumberOfMessages = GetNumberOfFilesInFolder(accountDir); TestTracer.WriteTraceInfo("{0}/{1}", actualNumberOfMessages, numberOfMessages); Assert.AreEqual(numberOfMessages, actualNumberOfMessages); }, TimeSpan.FromSeconds(30), TimeSpan.FromHours(12)); _domain.Delete(); }
public void TestSendToTooManyRecipients() { hMailServer.Accounts accounts = _domain.Accounts; SingletonProvider <TestSetup> .Instance.AddAccount(accounts, string.Format("*****@*****.**"), "test"); var sock = new TcpConnection(); sock.Connect(25); sock.ReadUntil("\r\n"); string result; sock.Send("EHLO test.com\r\n"); result = sock.ReadUntil("\r\n"); Assert.IsTrue(result.StartsWith("250")); sock.Send("MAIL FROM: [email protected]\r\n"); result = sock.ReadUntil("\r\n"); Assert.IsTrue(result.StartsWith("250")); const int recipientCount = 51000; for (int i = 1; i <= recipientCount; i++) { string address = string.Format("test{0}@gmail.com", i); sock.Send(string.Format("RCPT TO: <{0}>\r\n", address)); result = sock.ReadUntil("\r\n"); if (i <= 50000) { Assert.IsTrue(result.StartsWith("250")); } else { Assert.IsFalse(result.StartsWith("250")); } if (i % 100 == 0) { TestTracer.WriteTraceInfo("{0}/{1}", i, recipientCount); } } }
public void TestSendViaSpamAssassin() { CustomAsserts.AssertSpamAssassinIsRunning(); SingletonProvider <TestSetup> .Instance.GetApp().Settings.AntiSpam.SpamAssassinEnabled = true; string dataDir = Path.Combine(SingletonProvider <TestSetup> .Instance.GetApp().Settings.Directories.DataDirectory, "test.com"); string accountDir = Path.Combine(dataDir, "test"); int memoryUsage = Shared.GetCurrentMemoryUsage(); int maxMemoryUsage = memoryUsage + 2; const int numberOfMessages = 100; var mail = new MailMessage(); mail.From = new MailAddress("*****@*****.**"); mail.To.Add("*****@*****.**"); mail.Subject = "Automatic server test"; mail.Body = "Automatic server test"; mail.BodyEncoding = Encoding.GetEncoding(1252); mail.SubjectEncoding = Encoding.GetEncoding(1252); for (int i = 1; i <= numberOfMessages; i++) { var oClient = new SmtpClient("localhost", 25); oClient.Send(mail); if (i % 5 == 0) { Shared.AssertLowMemoryUsage(maxMemoryUsage); TestTracer.WriteTraceInfo("{0}/{1}", i, numberOfMessages); } } WaitForFilesInFolder(accountDir, numberOfMessages); _domain.Delete(); }
public void TestLongSMTPCommand() { var socket = new TcpConnection(); socket.Connect(25); // Build a large string... var sb = new StringBuilder(); sb.Append("A01"); for (int i = 0; i < 1000000; i++) { sb.Append("01234567890"); } sb.Append(Environment.NewLine); for (int i = 0; i < 100; i++) { try { socket.Send(sb.ToString()); } catch (Exception) { return; } if ((i % 10) == 0) { TestTracer.WriteTraceInfo("{0}/{1}", i, 100); } } socket.Send("\r\n"); socket.Receive(); socket.Disconnect(); }
public void TestManyTCPIPConnections() { LogHandler.DeleteCurrentDefaultLog(); const int count = 1000; List <TcpConnection> sockets = new List <TcpConnection>(); for (int i = 1; i <= count; i++) { TcpConnection socket = new TcpConnection(); Assert.IsTrue(socket.Connect(25)); if ((i % 10) == 0) { TestTracer.WriteTraceInfo("{0}/{1}", i, 1000); } sockets.Add(socket); } foreach (TcpConnection socket in sockets) { socket.Disconnect(); } RetryHelper.TryAction(() => { string log = LogHandler.ReadCurrentDefaultLog(); string connectionCreated = "TCP - 127.0.0.1 connected to 127.0.0.1:25."; string connectionEnded = "Ending session "; var created = Regex.Matches(log, connectionCreated); var ended = Regex.Matches(log, connectionEnded); Assert.AreEqual(count, created.Count); Assert.AreEqual(count, ended.Count); }, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(30)); }
public void Send100MBMessage() { long memoryUsage = Shared.GetCurrentMemoryUsage(); _application.Settings.MaxMessageSize = 0; TcpConnection socket = new TcpConnection(); socket.Connect(25); socket.Receive(); socket.Send("HELO test.com\r\n"); socket.Receive(); // Build a large string... StringBuilder sb = new StringBuilder(); sb.Append("A01"); for (int i = 0; i < 10000; i++) { sb.Append("01234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890\r\n"); } int length = sb.Length; sb.Append(Environment.NewLine); socket.Send("MAIL FROM: [email protected]\r\n"); socket.Receive(); socket.Send("RCPT TO: [email protected]\r\n"); socket.Receive(); socket.Send("DATA\r\n"); socket.Receive(); for (int i = 1; i <= 100; i++) { Shared.AssertLowMemoryUsage(memoryUsage + 30); try { socket.Send(sb.ToString()); } catch (Exception) { return; } if ((i % 10) == 0) { TestTracer.WriteTraceInfo("{0}/{1}", i, 1000); } } socket.Send("\r\n.\r\n"); string result = socket.Receive(); Assert.IsTrue(result.StartsWith("250")); socket.Send("QUIT\r\n"); result = socket.Receive(); socket.Disconnect(); Pop3ClientSimulator.AssertMessageCount(_domain.Accounts[0].Address, "test", 1); }