From e191b59233e333050ec4133d97f12e75ea5fa391 Mon Sep 17 00:00:00 2001 From: Mykolas Glinskis Date: Tue, 29 Nov 2016 18:28:22 +0100 Subject: [PATCH] Tests: include testcase for "couldn't read packet length" bug It seems that after triggering a FloodException, and waiting the required time to be able to use Telegram again, TLSharp throws an exception. I include the way to reproduce this bug as an [Ignore]d test with the hope that someone may help me fix the problem soon. For reference, the whole stacktrace of the exception was: Test Name: FloodExceptionShouldNotCauseCannotReadPackageLengthError Test FullName: TLSharp.Tests.TLSharpTestsVS.FloodExceptionShouldNotCauseCannotReadPackageLengthError Test Source: D:\Projects\GitHub\TLSharp\TLSharp.Tests.VS\TLSharpTestsVs.cs : line 72 Test Outcome: Failed Test Duration: 0:04:30.7467012 Result StackTrace: at TLSharp.Core.Network.TcpTransport.d__4.MoveNext() in D:\Projects\GitHub\TLSharp\TLSharp.Core\Network\TcpTransport.cs:line 39 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at TLSharp.Core.Network.MtProtoSender.d__9.MoveNext() in D:\Projects\GitHub\TLSharp\TLSharp.Core\Network\MtProtoSender.cs:line 139 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at TLSharp.Core.TelegramClient.d__8.MoveNext() in D:\Projects\GitHub\TLSharp\TLSharp.Core\TelegramClient.cs:line 76 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at TLSharp.Tests.TLSharpTests.d__54.MoveNext() in D:\Projects\GitHub\TLSharp\TLSharp.Tests\TLSharpTests.cs:line 329 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at TLSharp.Tests.TLSharpTestsVS.d__9.MoveNext() in D:\Projects\GitHub\TLSharp\TLSharp.Tests.VS\TLSharpTestsVs.cs:line 68 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at TLSharp.Tests.TLSharpTests.d__55.MoveNext() in D:\Projects\GitHub\TLSharp\TLSharp.Tests\TLSharpTests.cs:line 340 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at TLSharp.Tests.TLSharpTestsVS.d__10.MoveNext() in D:\Projects\GitHub\TLSharp\TLSharp.Tests.VS\TLSharpTestsVs.cs:line 73 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() Result Message: Test method TLSharp.Tests.TLSharpTestsVS.FloodExceptionShouldNotCauseCannotReadPackageLengthError threw exception: System.InvalidOperationException: Couldn't read the packet length --- TLSharp.Tests.NUnit/Test.cs | 7 +++++++ TLSharp.Tests.VS/TLSharpTestsVs.cs | 6 ++++++ TLSharp.Tests/TLSharpTests.cs | 16 ++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/TLSharp.Tests.NUnit/Test.cs b/TLSharp.Tests.NUnit/Test.cs index bf06d64..7c390db 100644 --- a/TLSharp.Tests.NUnit/Test.cs +++ b/TLSharp.Tests.NUnit/Test.cs @@ -68,5 +68,12 @@ namespace TLSharp.Tests { await base.CheckPhones(); } + + [Test] + [Ignore("FIXME")] + public override async Task FloodExceptionShouldNotCauseCannotReadPackageLengthError() + { + await base.FloodExceptionShouldNotCauseCannotReadPackageLengthError(); + } } } diff --git a/TLSharp.Tests.VS/TLSharpTestsVs.cs b/TLSharp.Tests.VS/TLSharpTestsVs.cs index 8167f91..fff25b6 100644 --- a/TLSharp.Tests.VS/TLSharpTestsVs.cs +++ b/TLSharp.Tests.VS/TLSharpTestsVs.cs @@ -67,5 +67,11 @@ namespace TLSharp.Tests { await base.CheckPhones(); } + [TestMethod] + [Ignore] + public override async Task FloodExceptionShouldNotCauseCannotReadPackageLengthError() + { + await base.FloodExceptionShouldNotCauseCannotReadPackageLengthError(); + } } } diff --git a/TLSharp.Tests/TLSharpTests.cs b/TLSharp.Tests/TLSharpTests.cs index 1779c67..3b2236a 100644 --- a/TLSharp.Tests/TLSharpTests.cs +++ b/TLSharp.Tests/TLSharpTests.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using TeleSharp.TL; using TeleSharp.TL.Messages; using TLSharp.Core; +using TLSharp.Core.Network; using TLSharp.Core.Requests; using TLSharp.Core.Utils; @@ -330,5 +331,20 @@ namespace TLSharp.Tests var result = await client.IsPhoneRegisteredAsync(NumberToAuthenticate); Assert.IsTrue(result); } + public virtual async Task FloodExceptionShouldNotCauseCannotReadPackageLengthError() + { + for (int i = 0; i < 50; i++) + { + try + { + await CheckPhones(); + } + catch (FloodException floodException) + { + Console.WriteLine($"FLOODEXCEPTION: {floodException}"); + Thread.Sleep(floodException.TimeToWait); + } + } + } } }