Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[.NET][Unit Testing] FromJson throws exceptions when running unit tests in parallel #3509

Closed
Rufus1123 opened this issue Oct 3, 2019 · 5 comments · Fixed by #3548
Closed
Assignees

Comments

@Rufus1123
Copy link

Platform

.NET
botframework

Version of SDK

NuGet version 1.2.3

Details

I have multiple dialogs and multiple tests for each dialog in my chatbot project. I use cards in these dialogs, which are obtained from json files. When running all my tests, I get the following exception for most of the tests:

Message:
System.InvalidOperationException : Stack empty.
Stack Trace:
at Stack1.ThrowForEmptyStack() at Stack1.Peek()
at ParseContext.PopElement()
at AdaptiveTypedElementConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
at JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
at JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at JsonSerializerProxy.DeserializeInternal(JsonReader reader, Type objectType)
at WhereSelectEnumerableIterator2.MoveNext() at WhereSelectEnumerableIterator2.ToList()
at Enumerable.ToList[TSource](IEnumerable`1 source)
at JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
at JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at JsonSerializerInternalReader.Populate(JsonReader reader, Object target)
at JsonSerializerProxy.PopulateInternal(JsonReader reader, Object target)
at AdaptiveTypedElementConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
at AdaptiveCardConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
at JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
at JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at AdaptiveCard.FromJson(String json)

and one test returns the following error:

Message:
System.NullReferenceException : Object reference not set to an instance of an object.
Stack Trace:
at ParseContext.PopElement()
at AdaptiveTypedElementConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
at JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
at JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at JsonSerializerProxy.DeserializeInternal(JsonReader reader, Type objectType)
...

When running the unit tests one by one, all of the pass.
It looks like AdaptiveCards.FromJson cannot handle multiple simultaneous calls.

@Rufus1123 Rufus1123 added the Bug label Oct 3, 2019
@ghost ghost added the Triage-Needed label Oct 3, 2019
@Rufus1123 Rufus1123 changed the title [.NET][Unit Testing] [FromJson throws exceptions when running unit tests in parallel] [.NET][Unit Testing] FromJson throws exceptions when running unit tests in parallel Oct 3, 2019
@ghost ghost removed the Triage-Needed label Oct 3, 2019
@shalinijoshi19
Copy link
Member

Hey @nesalang could you help pick this up? Thanks

@jwoo-msft
Copy link
Member

Hey @nesalang could you help pick this up? Thanks

sure

@jwoo-msft
Copy link
Member

@shalinijoshi19
from the log, the error happened in ParseContext. ParseContext is a static class, and PopElement and PushElement probably ran into synchronization issue.

in discussion with @paulcam206, we have two options:
one is adding mutex
second is making ParseContext an instance variable, and set the lifetime to be same as its root card.

second option seems better choice in terms of the performance from user perspective since we don't have to use computationally expensive mutex lock and create a bottleneck, but making non static will involve more work as we need to plumb down the parse context.

@ghost
Copy link

ghost commented Nov 5, 2019

🎉This issue was addressed in #, which has now been successfully released as [email protected].:tada:

@shaktikumar-singh
Copy link

shaktikumar-singh commented Nov 13, 2024

Issue is not fixed yet, I got this same issue. Had to stop running tests in parallel. But this might came in normal flow as well when many users will use the application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants