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

Fixes #12479: Set HttpContext before using ShellScope in Unit Tests #12480

Merged
merged 7 commits into from
Sep 29, 2022

Conversation

jtkech
Copy link
Member

@jtkech jtkech commented Sep 23, 2022

Fixes #12479

The failing report is there for a while, it doesn't break the unit tests as the exception is catched in our invoke extension, the error is only logged. For now what I saw from the trace is on a content manager loading an item.

Content item loading...
...
HtmlBodyPartHandler => IShortcodeService =>
IShortcodeProvider => AssetUrlShortcodeProvider  =>
IOptions<ResourceManagementOptions> =>
ResourceManagementOptionsConfiguration =>
NRE  on _pathBase = httpContextAccessor.HttpContext.Request.PathBase;

So I'm adding null operators step by step for testing

@jtkech
Copy link
Member Author

jtkech commented Sep 23, 2022

Okay it removes the fail report, I will remove null operator step by step.

@jtkech
Copy link
Member Author

jtkech commented Sep 23, 2022

Okay so this is the HttpContext that is null.

Looks like that in unit tests we are getting items => item loading => part coordinator, part handlers including HtmlBodyPartHandler, and then the DI injections as described above until the NRE.

Time to sleep, will see tomorrow ;)

@jtkech
Copy link
Member Author

jtkech commented Sep 23, 2022

Okay some unit tests call LuceneIndexingService.ProcessContentItemsAsync() which uses contentManager.GetAsync(), and then fail on the null HttpContext described above.

So in unit tests we would need to set an HttpContext each time we use shellScope.UsingAsync() as we do for example in background tasks, but for now I only did it where it was failing.

@jtkech
Copy link
Member Author

jtkech commented Sep 24, 2022

  • Okay, so for Unit Tests I opted to make an UsingTenantScopeAsync() method that ensures that an HttpContext is set (as in a background task) and then calls ShellScope.UsingAsync() as before.

  • The above method is defined in the SiteContext base class where I also defined the ShellHost property in place of having to define it in each derived classes.

@jtkech jtkech changed the title Testing NRE in Unit Tests Fixes #12479: Set HttpContext before using ShellScope in Unit Tests Sep 24, 2022
@sebastienros sebastienros merged commit c35ffc6 into main Sep 29, 2022
@sebastienros sebastienros deleted the jtkech/unit-tests branch September 29, 2022 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unit Test reporting "Fail" in CI
3 participants