Hi Guys,
i am getting some weired exceptions when running our unittests on our build servers. when i disable all 19.1.3 optimization for our testapplication they are running fine. is this recommended for running unittests? i did now the following and unittests are running fine now:
public class TestApplication : XafApplication
{
public TestApplication()
{
this.ShowViewStrategy = new TestShowViewStrategy(this);
DevExpress.ExpressApp.Model.ModelXmlReader.UseXmlReader = false;
DevExpress.ExpressApp.Model.Core.ModelNode.UseDefaultValuesCache = false;
DevExpress.ExpressApp.Core.ControllersManager.UseParallelBatchControllerCreation = false;
DevExpress.ExpressApp.ApplicationModulesManager.UseParallelTypesCollector = false;
DevExpress.ExpressApp.ApplicationModulesManager.UseStaticCache = false;
DevExpress.Persistent.Base.ReflectionHelper.UseAssemblyResolutionCache = false;
}
Hello Noxe,
We have an internal issue related to RunSetupInNewThread, which we have yet to fix. It may be related.
Would you please provide us with the exception error message and call stacks? If it is stably reproducible, please provide us with a debuggable sample.
I am happy to hear that you were able to temporarily bypass it by disabling these toggles.
Hi man,
problem is i cannot repro it locally - only happens on build server. i think it is not related to RunSetupInNewThread since this is only available for WinApplication?
some exptions:
ie Initialisierungsmethode 'VenDoc.Module.BuildingSite.UnitTests.Classes.RootDocument.RootDocumentTests.Initialize' hat eine Ausnahme ausgelöst. DevExpress.ExpressApp.Utils.CodeGeneration.CompilerErrorException: Cannot compile the generated code. Please inspect the generated code via this exception's SourceCode property. The following errors occurred: (12585, 52): Der Typ- oder Namespacename 'ModelObjectView' konnte nicht gefunden werden. (Fehlt eine Using-Direktive oder ein Assemblyverweis?) . bei DevExpress.ExpressApp.Utils.CodeGeneration.CSCodeCompiler.RaiseCompilerException(String sourceCode, CompilerResults compilerResults) bei DevExpress.ExpressApp.Utils.CodeGeneration.CSCodeCompiler.Compile(String sourceCode, String[] references, String assemblyFile) bei DevExpress.ExpressApp.Model.Core.GlobalModelAssemblyRegistry.CompileModelAssembly(ICollection`1 customInterfacesToGenerate, ClassDescriptionCollection classDescriptions, CustomLogics customLogics, ModelInterfaceExtenders interfaceExtenders, String assemblyFileAbsolutePath) bei DevExpress.ExpressApp.Model.Core.GlobalModelAssemblyRegistry.Get(ICollection`1 customInterfacesToGenerate, ClassDescriptionCollection classDescriptions, CustomLogics customLogics, ModelInterfaceExtenders interfaceExtenders, String assemblyFileAbsolutePath) bei DevExpress.ExpressApp.Model.Core.ModelApplicationCreator.GetModelAssembly(ModelApplicationCreatorProperties properties) bei DevExpress.ExpressApp.Model.Core.ModelApplicationCreator.CreateCreatorInfo(ModelApplicationCreator modelApplicationCreator) bei DevExpress.ExpressApp.Model.Core.ModelApplicationCreator.get_CreatorInfo() bei DevExpress.ExpressApp.Model.Core.ModelApplicationCreator.AddValidator[T](IModelNodeValidator`1 validator) bei DevExpress.ExpressApp.SystemModule.SystemModule.AddModelNodeValidators(IModelNodeValidatorRegistrator validatorRegistrator) bei DevExpress.ExpressApp.ApplicationModelManager.SetupModelApplicationCreator(ModelApplicationCreator creator, IEnumerable`1 modules, IEnumerable`1 aspects) bei DevExpress.ExpressApp.ApplicationModelManager.Setup(ITypesInfo typesInfo, IEnumerable`1 boModelTypes, IEnumerable`1 modules, IEnumerable`1 controllers, IEnumerable`1 applicationLocalizerTypes, IEnumerable`1 applicationAspects, ModelStoreBase applicationModelDifferenceStore, String modelAssemblyFile) bei DevExpress.ExpressApp.XafApplication.CreateModelManager(IEnumerable`1 boModelTypes) bei DevExpress.ExpressApp.XafApplication.Setup(ExpressApplicationSetupParameters parameters) bei DevExpress.ExpressApp.XafApplication.SetupCore(String applicationName, IList`1 objectSpaceProviders, ApplicationModulesManager modulesManager, ISecurityStrategyBase security) bei DevExpress.ExpressApp.XafApplication.Setup(String applicationName, IObjectSpaceProvider objectSpaceProvider, String[] moduleAssemblies, ISecurityStrategyBase security) bei DevExpress.ExpressApp.XafApplication.Setup(String applicationName, IObjectSpaceProvider objectSpaceProvider) bei VenDoc.Module.BuildingSite.UnitTests.Classes.RootDocument.RootDocumentTests.Initialize() in C:\Program Files\TeamCity\CheckOut\VenDoc\VenDoc.Module.BuildingSite.UnitTests\Classes\RootDocument\RootDocumentTests.cs:Zeile 47.
Die Testmethode "VenDoc.Module.BuildingSite.UnitTests.Classes.ShowBookedMaterial.ShowBookedMaterialTests.OpenShowBookedMaterial" hat eine Ausnahme ausgelöst: System.Exception: An error with number 1041 has occurred. Error message: Unable to find a detail view for the 'VenDoc.Module.BuildingSite.ShowBookedMaterialParameters' object type bei DevExpress.ExpressApp.XafApplication.CheckDetailViewId(String detailViewId, Type objectType) bei DevExpress.ExpressApp.XafApplication.CreateDetailView(IObjectSpace objectSpace, String detailViewID, Boolean isRoot, Object obj, Boolean isDelayedObjectLoading) bei DevExpress.ExpressApp.XafApplication.CreateDetailView(IObjectSpace objectSpace, Object obj, View sourceView) bei DevExpress.ExpressApp.XafApplication.CreateDetailView(IObjectSpace objectSpace, Object obj) bei VenDoc.Module.BuildingSite.UnitTests.Classes.ShowBookedMaterial.ShowBookedMaterialTests.OpenShowBookedMaterial() in C:\Program Files\TeamCity\CheckOut\VenDoc\VenDoc.Module.BuildingSite.UnitTests\Classes\ShowBookedMaterial\ShowBookedMaterialTests.cs:Zeile 141.
others are NullReferenceExptions:
Die Testmethode "VenDoc.Module.Documents.UnitTests.Controller.DocumentController.DeliveryNoteDocumentTests.Zwei_Auftraege_ueberleiten_Status_Test" hat eine Ausnahme ausgelöst: System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt. bei VenDoc.Module.Documents.UnitTests.Controller.DocumentController.DeliveryNoteDocumentTests.ConvertOrderDocumentsToDeliveryNoteDocument() in C:\Program Files\TeamCity\CheckOut\VenDoc\VenDoc.Module.Documents.UnitTests\Controller\DocumentController\DeliveryNoteDocumentTests.cs:Zeile 202. bei VenDoc.Module.Documents.UnitTests.Controller.DocumentController.DeliveryNoteDocumentTests.Zwei_Auftraege_ueberleiten_Status_Test() in C:\Program Files\TeamCity\CheckOut\VenDoc\VenDoc.Module.Documents.UnitTests\Controller\DocumentController\DeliveryNoteDocumentTests.cs:Zeile 173. corresponding code line:
var action = convertDocumentController.Actions.Where(r => r.Id == "ConvertDocument").FirstOrDefault() as SingleChoiceAction; ``````
Thank you for your update. That's right. BTW, our issue is also reproducible only on the build sever and is sporadic…
I hate to ask for this you guys, but it is possible to narrow it down by turning on the toggles one by one…However, I bet it is related to UseDefaultValuesCache.
If we have any additional information, we will let you know. Two responsible developers are currently researching this. Really sorry for the inconvenience, Noxe…
absolutely no problem Dennis! i try to narrow it down as you suggest - gut i guess it will be after my vacation next week ;)
Before you go, do you reset the XafTypesInfo singleton between tests?
Internally, we use HardReset in our tests that are run in parallel:
[C#]
I suggest you stick with this approach in the future.thx - currently i test the toggles - will report back soon.
and thx about hardreset - no, we dont use it currently.
ok - i can remove all toggles but leave this one:
ApplicationModulesManager.UseStaticCache = false;
Thank you for the quick update, Man!
My colleagues also suggest that you add the following constructors to your TestApplication class:
public TestApplication() : this(XafTypesInfo.Instance) { } public TestApplication(DevExpress.ExpressApp.DC.ITypesInfo typesInfo) : base(typesInfo) { }
thx for the update - added the ctor's - but does not change anything. when removing UseStaticCache the errors come back
btw - sorry, seems not 100% true - also failed now with UseStaticCache - seems bit random currently…
damn - seems i should stop testing now, was my fault ;)
removing UseStaticCache = error
adding UseStaticCache = false = tests are OK
Man,
Have some rest, seriously;-)
;)
Hello, Martin.
The static types cache is automatically enabled in release builds only. It seems that you run unit tests with a release (optimized) build of your assemblies, which is quite unusual. Would you please explain why you use this configuration? Please note that if tests are run in parallel in the same application domain, they may influence each other via static variables and fail. In this scenario, you should avoid using static variables (XafTypesInfo, XpoDefault, etc.) and disable all static caches.
We will add a corresponding note to the Performance enhancements in XAF v19.1 for all supported platforms article.
Hi Michael,
"Would you please explain why you use this configuration?" - no special reason - we simply added an unittest build step after our release build step ;)
Thank you for the reply!
Hi Martin,
I want to follow up in this ticket, because we recently published a series of articles regarding how to write unit tests for different XAF scenarios in a lightweight way. This approach uses mocks and does not create a real XAF application. Your test performance should be much better with this approach. I hope you will find them useful. Please check:
How to write lightweight unit tests for XAF Actions, Controllers and other custom UI logic
By the way, did you manage to write a unit test for this particular scenario? If not, what difficulties are you still facing? This case may be a topic for our new article.
Ho Gosha,
thx - i am already following your post - they are really great!! thx for this - keep them coming :) but i had no time yet to fully study them!
You are welcome, Martin! If you have interesting cases for unit tests, don't hesitate to share your ideas so that we can continue our series!
Hi Gusha,
one thing which comes in my mind as for interesting cases would be how to correctly test business classes logic with XPO. would be great to see your recommendations. setup xaftypesinfo / objectspaceprovider? (we use inmemory currently), securitysystem and so on…
Hello Martin,
I've created a separate ticket on your behalf (T863708: How to unit test business classes' logic with XPO).