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

Log errors when running UnitTest suite #3811

Closed
pkernevez opened this issue Oct 19, 2023 · 3 comments · Fixed by #5894 or #5911
Closed

Log errors when running UnitTest suite #3811

pkernevez opened this issue Oct 19, 2023 · 3 comments · Fixed by #5894 or #5911
Labels
Bug Something isn't working Core Engine

Comments

@pkernevez
Copy link
Contributor

I follow the old video : https://www.youtube.com/watch?v=MmUtdEkLM6M

I import the Pester module that should have been had after the recording of the video:

Install-Module Pester -Force -SkipPublisherCheck -Scope AllUsers

Then

#  I go to tests folder:
cd $DSC_GIT_ROOT/Tests

# Import TestHarness
Import-Module -Verbose -Force ./TestHarness.psm1

# Then run the tests
Invoke-TestHarness -Verbose -IgnoreCodeCoverage

When running it from VSCode terminal, I have a lot of errors (100s, because it logs 1 to 3 errors per unit test) like bellow. Seems to be same as #828 , that has been fixed.

[2023/10/19 08:09:53]
{NotSpecified}
System.Management.Automation.MethodInvocationException: Exception calling "SourceExists" with "1" argument(s): "The source was not found, but some or all event logs could not be searched.  Inaccessible logs: Security, State."
 ---> System.Security.SecurityException: The source was not found, but some or all event logs could not be searched.  Inaccessible logs: Security, State.
   at System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly, Boolean wantToCreate)
   at System.Diagnostics.EventLog.SourceExists(String source, String machineName, Boolean wantToCreate)
   at CallSite.Target(Closure, CallSite, Type, String)
   --- End of inner exception stack trace ---
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
"Could not write to event log Source {MSFT_AADCrossTenantAccessPolicy} EntryType {Warning} Message {<M365DSCEvent>
    <ConfigurationDrift Source="MSFT_AADCrossTenantAccessPolicy">
        <ParametersNotInDesiredState>
            <Param Name="AllowedCloudEndpoints"><CurrentValue>microsoftonline.com</CurrentValue><DesiredValue>microsoftonline.us</DesiredValue></Param>
        </ParametersNotInDesiredState>
    </ConfigurationDrift>
    <DesiredValues>
        <Param Name ="Credential">System.Management.Automation.PSCredential</Param>
        <Param Name ="AllowedCloudEndpoints">microsoftonline.us</Param>
        <Param Name ="Ensure">Present</Param>
        <Param Name ="IsSingleInstance">Yes</Param>
        <Param Name ="DisplayName">MyXTAPPolicy</Param>
    </DesiredValues>
</M365DSCEvent>}"
at Add-M365DSCEvent, Y:\Microsoft365DSC\Modules\Microsoft365DSC\modules\M365DSCLogEngine.psm1: line 194
@andikrueger andikrueger added Bug Something isn't working Core Engine Pending Information and removed Bug Something isn't working labels Oct 19, 2023
@andikrueger
Copy link
Collaborator

Could you try to run the unit tests within an elevated powershell session?

@pkernevez
Copy link
Contributor Author

pkernevez commented Oct 19, 2023

In this case, the errors disappear.
But I don't want to run Unit Test with admin privileges.

@andikrueger
Copy link
Collaborator

This is very true. The issue is within the Log-Engine. We added some checks in the past to not try to create a new event log. Looks like we need to add a check as well not to write to the error log in this case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Core Engine
Projects
None yet
2 participants