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

Implement NLog in unit test project #14347

Open
hyzx86 opened this issue Sep 16, 2023 · 4 comments
Open

Implement NLog in unit test project #14347

hyzx86 opened this issue Sep 16, 2023 · 4 comments
Milestone

Comments

@hyzx86
Copy link
Contributor

hyzx86 commented Sep 16, 2023

Currently, unit tests catch very limited exception information,
Many exceptions that occur during the installation process are ignored
Can I use the log function to quickly locate anomalies?

@hyzx86 hyzx86 changed the title Implement logging functionality in a unit test project Implement NLog in unit test project Sep 16, 2023
@hishamco
Copy link
Member

Could you please ellaborate?

@hyzx86
Copy link
Contributor Author

hyzx86 commented Sep 17, 2023

Some exceptions during migration will not directly cause process interruption, but once an exception occurs, it will have a serious impact on the integrity of system functions

Just like , the exception caused by the MySql /Postgresql syntax problem mentioned earlier did not interrupt the migration process

#14338

#11359

It may be due to some considerations that the change exception is not thrown, but if we can also work with log file scanning to eliminate some errors that are not easy to find, it is also a good way

And CI/CD will be able to find these errors automatically

@hyzx86
Copy link
Contributor Author

hyzx86 commented Sep 17, 2023

Just use below code . Maybe there should be a better way

        [Fact]
        public async Task ValidateLogErrors()
        {

            using var context = new ScriptQueryContext();
            //初始化测试环境
            await context.InitializeAsync();
            await context.UsingTenantScopeAsync(scope =>
            {
                var fileTarget = (FileTarget)LogManager.Configuration.FindTargetByName("file");
                var logFilePath = fileTarget.FileName.Render(new LogEventInfo { TimeStamp = DateTime.Now });

                Assert.True(File.Exists(logFilePath));

                var hasError = AppFileHelper.ReadLines(logFilePath).Any(x => x.Contains("|ERROR|"));
                Assert.False(hasError);

                return Task.CompletedTask;
            });
        }

image

@sebastienros
Copy link
Member

Like a functional test to catch exceptions during setup that might get through otherwise.

@sebastienros sebastienros added this to the 1.x milestone Sep 28, 2023
This was referenced Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants