public void TestSmgpLifetimeSimple() { var client = new SmgpSmsClient(_configurations); Task.Run(async() => { await client.StartAsync(); await Task.Delay(30000); await client.StopAsync(); }).Wait(); }
public void TestSmgpUplinkDeliverSimple() { var client = new SmgpSmsClient(_configurations); Task.Run(async() => { await client.StartAsync(); client.SmsDeliverReceived += (sender, e) => { var deliver = e.Deliver as SmgpMessageDeliver; Assert.IsNotNull(deliver); Assert.IsInstanceOfType(deliver, typeof(SmgpMessageDeliver)); Assert.IsTrue(deliver.Command == SmgpCommands.Deliver); Debug.WriteLine("上行短信内容: " + deliver.MessageConent); }; await Task.Delay(10000); await client.StopAsync(); }).Wait(); }
public void TestSmgpSendSmsPerformanceByTime() { var client = new SmgpSmsClient(_configurations); var receivers = new string[] { "13979121569" }; var content = "测试短信"; var totalSpan = TimeSpan.FromMinutes(5); int count = 0; int responseCount = 0; int reportCount = 0; Task.Run(async() => { client.SmsResponseReceived += (sender, e) => { responseCount++; }; client.SmsReportReceived += (sender, e) => { reportCount++; }; await client.StartAsync(); var start = DateTime.Now; DateTime?responseComplete = null; DateTime?reportComplete = null; var updateStamp = DateTime.Now; while ((DateTime.Now - start) < totalSpan) { await client.SendSmsAsync(receivers, content); count++; await Task.Delay(0); if ((DateTime.Now - updateStamp) >= TimeSpan.FromMinutes(1)) { updateStamp = DateTime.Now; Debug.WriteLine("{0} {1} {2} ", count, responseCount, reportCount); } } var waitSpan = TimeSpan.FromSeconds(count / 100); var waitStart = DateTime.Now; while ((DateTime.Now - waitStart) < waitSpan) { if ((DateTime.Now - updateStamp) >= TimeSpan.FromMinutes(1)) { updateStamp = DateTime.Now; Debug.WriteLine("{0} {1} {2} ", count, responseCount, reportCount); } if (responseComplete == null && responseCount == count) { responseComplete = DateTime.Now; } if (reportComplete == null && reportCount == count) { reportComplete = DateTime.Now; } if (responseCount == count && reportCount == count) { break; } await Task.Delay(50); } await client.StopAsync(); Debug.WriteLine("Messages Sent {0}", count); Debug.WriteLine("Rsponses {0}", responseCount); Debug.WriteLine("Reports {0}", reportCount); if (responseComplete.HasValue) { var duration = (responseComplete.Value - start).TotalSeconds; Debug.WriteLine("Submit spent {0} seconds on {1} messages, throughput : {2} mps", duration, count, count / duration); } if (reportComplete.HasValue) { var duration = (reportComplete.Value - start).TotalSeconds; Debug.WriteLine("Report spent {0} seconds on {1} messages, throughput : {2} mps", duration, count, count / duration); } }).Wait(); }