5
Views
1
Comments
[Testing Framework] EspaceInvalidateCache does not seem to work when running in a test case
testing-framework
Reactive icon
Forge asset by Leonardo Fernandes
Application Type
Reactive

Great work with this component. It's definitely the best for unit testing in O11.

I do have a situation, though. It seems the EspaceInvalidateCache action does not work inside test case actions.

Here's a super simple example to reproduce it:

GetCachedDateTime returns CurrDateTime() and has a 5 min cache. I pass its output to AssertFail just to see it in the Test Console. Even though I invoke EspaceInvalidateCache before it, the first datetime output sticks for the full cache duration.

If I remove the BeginTestCase call at the beginning, the datetime value is cleared correctly. This indicates that something from TestingFramework is interfering with cache invalidation. Any ideas?

2019-10-27 01-32-56
Caio Santana Magalhães
 
MVP

After some digging, I found what the problem is.

In the source code of the TestingServerSideInstrumentation XIF, file Instrumentation.cs (line 100), there's this line that turns the InvalidateEspace method into a NOOP inside InitializeMockInstrumentation().

I think I understand what the thinking was by interpreting the context. The idea was to deactivate anything related to setting site properties inside tests. However, eSpace invalidation has broader usage than just site property setting, and disabling it has a larger blast radius than it should.

I have a number of tests that are currently failing because they share internally some action that gets cached when the first test case runs, and the other tests that follow inadvertently get the cached value generated by the first test case. I need to run EspaceInvalidateCache at the beginning of these tests, but because of this line in the XIF, this is not working.

I commented out this line and my tests stopped failing.

@Leonardo, I'd love it if you could push an update to Testing Framework without this NOOP patch. I think there's legit reasons for it to be removed, and I also hate having to customize Forge components making my version not in sync with the official one :-)

Thanks.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.