HodorNV / ALOps

ALOps
55 stars 24 forks source link

ALOps App Test Dialog Errors for NextMinor/NextMajor: You must choose a company before you can access the "Global Application User Settings" table. #742

Closed DanielGoehler closed 1 week ago

DanielGoehler commented 3 months ago

Describe the bug When testing against BC NextMinor or BC NextMajor with ALOpsAppTest you get an dialog error message:

You must choose a company before you can access the "Global Application User Settings" table.

the used yaml

NextMinor.yml

name: $(Build.BuildId)

variables:
  - group: 'ALOps Settings'

pool:
  name: BusinessCentralBuildAgents

trigger:
  - main

schedules:
  - cron: '0 12 * * 0'
    displayName: Weekly Next Minor Build on Sunday 12h (UTC)
    branches:
      include:
        - main
    always: true

stages:
  - template: templates/CompileAndTest.yml
    parameters:
      appversiontemplate: '?.?.*.0'
      alcodeanalyzer: 'AppSourceCop,CodeCop,PerTenantExtensionCop,UICop'
      selectVersions: ['NextMinor']
      countries: ['de']
      alsourcepath: '$(System.DefaultWorkingDirectory)/MainApp'

templates/CompileAndTest.yml

parameters:
  selectVersions: ['Current']
  artifacttype: 'Sandbox'
  countries: ['de']
  alcodeanalyzer: 'AppSourceCop,CodeCop,PerTenantExtensionCop,UICop'
  alsourcepath: ''
  appversiontemplate: ''

stages:
  - ${{each country in parameters.countries}}:
      - ${{each selectVersion in parameters.selectVersions}}:
          - stage: 'buildAndTest${{country}}${{selectVersion}}'
            displayName: 'Build Version ${{selectVersion}} for ${{country}}'
            pool:
              name: BusinessCentralBuildAgents
            jobs:
              - job: 'build${{country}}${{selectVersion}}'
                displayName: 'Job - Validate  ${{country}} ${{selectVersion}}'
                workspace:
                  clean: all # What to clean up before the job runs - outputs | resources | all
                steps:
                  - task: ALOpsDockerCreate@1
                    displayName: 'Create Docker Container'
                    inputs:
                      artifactcountry: '${{country}}'
                      versionselect: '${{selectVersion}}'
                      artifacttype: '${{parameters.artifacttype}}'
                      appversiontemplate: '${{parameters.appversiontemplate}}'
                      alsourcepath: '${{parameters.alsourcepath}}'
                      licensefile: '\\files\DevOps\Common\bc.bclicense'
                      accept_insider_eula: true

                  - task: ALOpsDockerStart@1
                    displayName: 'Start Docker Container'
                    inputs:
                      memory_gb: '8'

                  - task: ALOpsDockerWait@1
                    displayName: 'Wait for Docker Container'
                    inputs:
                      search_string: 'Ready for connections!'

                  - template: DownloadDependencies.yml # Template reference

                  - task: ALOpsAppPublish@1
                    displayName: 'Publish Dependencies'
                    inputs:
                      usedocker: true
                      nav_artifact_app_filter: '*.app'
                      batch_publish_folder: '$(System.ArtifactsDirectory)'

                  - task: ALOpsAppCompiler@1
                    displayName: 'App Compiler'
                    inputs:
                      usedocker: true
                      targetproject: 'MainApp/app.json'
                      al_analyzer: '${{parameters.alcodeanalyzer}}'
                      nav_app_version: '${{parameters.appversiontemplate}}'
                      publish_artifact: false

                  - task: ALOpsAppPublish@1
                    displayName: 'App Publish'
                    inputs:
                      usedocker: true
                      nav_artifact_app_filter: '*.app'

                  # TestApp
                  - task: ALOpsAppPublish@1
                    displayName: 'Install AL TestTool'
                    inputs:
                      usedocker: true
                      installaltesttool: true
                      install_al_app_names: |
                        System Application Test Library  
                        Library Variable Storage  
                        Permissions Mock  
                        Library Assert  
                        Any  
                        Test Runner  
                        Tests-TestLibraries
                      strictappnames: true

                  - task: ALOpsAppCompiler@1
                    displayName: 'Compile Test-App'
                    inputs:
                      usedocker: true
                      targetproject: 'TestApp/app.json'
                      nav_app_version: '${{parameters.appversiontemplate}}'
                      publish_artifact: false

                  - task: ALOpsAppPublish@1
                    displayName: 'Publish Test-App'
                    inputs:
                      usedocker: true
                      nav_artifact_app_filter: '*.app'

                  - task: ALOpsAppTest@1
                    displayName: 'Run TestSuite'
                    inputs:
                      usedocker: true
                      import_testtoolkit: false
                      testpage: '130455'
                      failed_test_action: Error
                    continueOnError: false

                  - task: PublishTestResults@2
                    displayName: 'Publish Test Results'
                    inputs:
                      testResultsFormat: 'XUnit'
                      testResultsFiles: '**/TestResults.xml'
                      testRunTitle: 'BC Test Results: $(Build.BuildId)'

                  - task: ALOpsDockerRemove@1
                    displayName: 'Remove Docker Container'
                    condition: always()

the output Also the complete output is necessary for us to see what is going on. Also use backtics:

##[section]Starting: Run TestSuite
==============================================================================
Task         : ALOps App Test
Description  : Run AL-TestSuite for Business Central
Version      : 1.463.5245
Author       : Hodor
Help         : Run Business Central Test-Suite and collect results.
==============================================================================
*** Validate configuration
*** Task Inputs:

name                           value
----                           -----
usedocker                       True
fixed_tag                           
nav_serverinstance                  
tenant                       default
companyname                         
profile                             
bc_username                         
bc_password                         
bc_authentication    NavUserPassword
bc_webclient_url                    
testfilter                          
disabledtests                       
show_available_tests            True
import_testtoolkit             False
import_action              Overwrite
testpage                      130455
testsuite                    DEFAULT
extensionid                         
installaltesttool              False
failed_test_action             Error
override_finsql_path                
resultfilename       TestResults.xml
testrunnercodeunitid                

True
*** For documentation, please visit   : https://www.alops.be/documentation

*** Importing required PS-Functions
*** Working folder: C:\agent\_work\1492\s
***
*** Prepare Docker Session
*** Connect Docker Session
*** Initiate Docker Session
*** Set Docker Container ErrorActionPreference = Stop
*** Copy Modules to Docker
*** Setup Docker Session
*** Checking for container-specific Test Assemblies
*** Using container-specific Test Assemblies
*** Import Modules in Docker Session
*** Import UI Client [C:\Run\DevOps\BCAppTest\bin\Microsoft.Dynamics.Framework.UI.Client.dll]
*** Selected module: [C:\Run\DevOps\BCAppTest\bin\Microsoft.Dynamics.Framework.UI.Client.dll]
*** Loading module: [C:\Run\DevOps\BCAppTest\bin\Microsoft.Dynamics.Framework.UI.Client.dll]
*** Import NewtonSoft JSON [C:\Program Files\Microsoft Dynamics NAV\240\Service\Management\Newtonsoft.Json.dll]
*** Import Modules in Docker Session: class_ClientContext
*** Test Context Url: https://4005c86d0b37/BC/cs?tenant=default
*** Setup BC Credentials in Docker
*** Resolve Docker Credentials
*** Set TCP Keep-Alive
*** Start TestSuite
*** Running TestSuite with authentication [NavUserPassword] with User [admin]
*** Run warm-up with page [130455]
*** Warm-up Client Context
ERROR DIALOG: You must choose a company before you can access the "Global Application User Settings" table.
*** Create Client Context
*** Get Available Tests for suite [DEFAULT] with page [130455]
Show dialog 00000000-0000-0000-0800-0000836bd2d2
Title: Dialog Error
ERROR DIALOG: You must choose a company before you can access the "Global Application User Settings" table.
##[error]Run-Test-Exception: Cannot open page 130455. You might need to import the test toolkit to the container and/or remove the folder  and retry. You might also have URL or Company name wrong.
*** Get XUnit Test file from [] to [C:\agent\_work\1492\s\]
##[error]Das Argument kann nicht an den Parameter "Path" gebunden werden, da es NULL ist.
##[section]Finishing: Run TestSuite
waldo1001 commented 2 months ago

Hm. Would you be able to test with a companyname in the parameter?

DanielGoehler commented 2 months ago

I added the companyname "CRONUS DE" but the result is the same:

##[section]Starting: Run TestSuite
==============================================================================
Task         : ALOps App Test
Description  : Run AL-TestSuite for Business Central
Version      : 1.463.5245
Author       : Hodor
Help         : Run Business Central Test-Suite and collect results.
==============================================================================
*** Validate configuration
*** Task Inputs:

name                           value
----                           -----
usedocker                       True
fixed_tag                           
nav_serverinstance                  
tenant                       default
companyname                CRONUS DE
profile                             
bc_username                         
bc_password                         
bc_authentication    NavUserPassword
bc_webclient_url                    
testfilter                          
disabledtests                       
show_available_tests            True
import_testtoolkit             False
import_action              Overwrite
testpage                      130455
testsuite                    DEFAULT
extensionid                         
installaltesttool              False
failed_test_action             Error
override_finsql_path                
resultfilename       TestResults.xml
testrunnercodeunitid                

True
*** For documentation, please visit   : https://www.alops.be/documentation

*** ALOps License:
  * Licensed To: prisma informatik GmbH (Organisation License)

*** Importing required PS-Functions
*** Working folder: C:\agent\_work\1495\s
***
*** Prepare Docker Session
*** Connect Docker Session
*** Initiate Docker Session
*** Set Docker Container ErrorActionPreference = Stop
*** Copy Modules to Docker
*** Setup Docker Session
*** Checking for container-specific Test Assemblies
*** Using container-specific Test Assemblies
*** Import Modules in Docker Session
*** Import UI Client [C:\Run\DevOps\BCAppTest\bin\Microsoft.Dynamics.Framework.UI.Client.dll]
*** Selected module: [C:\Run\DevOps\BCAppTest\bin\Microsoft.Dynamics.Framework.UI.Client.dll]
*** Loading module: [C:\Run\DevOps\BCAppTest\bin\Microsoft.Dynamics.Framework.UI.Client.dll]
*** Import NewtonSoft JSON [C:\Program Files\Microsoft Dynamics NAV\240\Service\Management\Newtonsoft.Json.dll]
*** Import Modules in Docker Session: class_ClientContext
*** Test Context Url: https://f27fee7e4361/BC/cs?tenant=default&company=CRONUS%20DE
*** Setup BC Credentials in Docker
*** Resolve Docker Credentials
*** Set TCP Keep-Alive
*** Start TestSuite
*** Running TestSuite with authentication [NavUserPassword] with User [admin]
*** Run warm-up with page [130455]
*** Warm-up Client Context
ERROR DIALOG: You must choose a company before you can access the "Global Application User Settings" table.
*** Create Client Context
*** Get Available Tests for suite [DEFAULT] with page [130455]
Show dialog 00000000-0000-0000-0800-0000836bd2d2
Title: Dialog Error
ERROR DIALOG: You must choose a company before you can access the "Global Application User Settings" table.
##[error]Run-Test-Exception: Cannot open page 130455. You might need to import the test toolkit to the container and/or remove the folder  and retry. You might also have URL or Company name wrong.
*** Get XUnit Test file from [] to [C:\agent\_work\1495\s\]
##[error]Das Argument kann nicht an den Parameter "Path" gebunden werden, da es NULL ist.
##[section]Finishing: Run TestSuite
waldo1001 commented 2 months ago

@DanielGoehler is this still a problem with the new build?

DanielGoehler commented 2 months ago

@waldo1001 Yes, but now only for a few repos. They all have the same pipelines with the same Test libraries. All are PTE projects and use the same dev licences. I don't see what the difference is.

DanielGoehler commented 2 months ago

@waldo1001 is it possible to disable the heat-up or add the company name to the heat-up call? I suspect this step as the problem.

image
waldo1001 commented 2 months ago

Disabling the warm-up won't help, because it will fail in one of the next steps.

Can you export the eventlog?

cfr: https://docs.alops.be/ALOpsSteps/Buildstepsv1/#alops_docker_remove

DanielGoehler commented 2 months ago

@waldo1001 Sure, attached you find the eventlog: 9c88fb310b_20240425_133422.zip

2024-04-25T11:34:08.7639182Z ##[section]Starting: Run TestSuite
2024-04-25T11:34:08.7671851Z ==============================================================================
2024-04-25T11:34:08.7672048Z Task         : ALOps App Test
2024-04-25T11:34:08.7672164Z Description  : Run AL-TestSuite for Business Central
2024-04-25T11:34:08.7672285Z Version      : 1.464.6041
2024-04-25T11:34:08.7672372Z Author       : Hodor
2024-04-25T11:34:08.7672472Z Help         : Run Business Central Test-Suite and collect results.
2024-04-25T11:34:08.7672600Z ==============================================================================
2024-04-25T11:34:09.7743295Z *** Validate configuration
2024-04-25T11:34:09.9997185Z *** Task Inputs:
2024-04-25T11:34:10.0002040Z 
2024-04-25T11:34:10.0101383Z name                           value
2024-04-25T11:34:10.0101968Z ----                           -----
2024-04-25T11:34:10.0102901Z usedocker                       True
2024-04-25T11:34:10.0103760Z fixed_tag                           
2024-04-25T11:34:10.0104395Z nav_serverinstance                  
2024-04-25T11:34:10.0105280Z tenant                       default
2024-04-25T11:34:10.0105959Z companyname                CRONUS DE
2024-04-25T11:34:10.0106787Z profile                             
2024-04-25T11:34:10.0107508Z bc_username                         
2024-04-25T11:34:10.0108320Z bc_password                         
2024-04-25T11:34:10.0109131Z bc_authentication    NavUserPassword
2024-04-25T11:34:10.0109822Z bc_webclient_url                    
2024-04-25T11:34:10.0110761Z testfilter                          
2024-04-25T11:34:10.0111479Z disabledtests                       
2024-04-25T11:34:10.0112316Z show_available_tests            True
2024-04-25T11:34:10.0113050Z import_testtoolkit             False
2024-04-25T11:34:10.0113889Z import_action              Overwrite
2024-04-25T11:34:10.0114987Z testpage                      130455
2024-04-25T11:34:10.0115826Z testsuite                    DEFAULT
2024-04-25T11:34:10.0117758Z extensionid                         
2024-04-25T11:34:10.0118160Z installaltesttool              False
2024-04-25T11:34:10.0118427Z failed_test_action             Error
2024-04-25T11:34:10.0119192Z override_finsql_path                
2024-04-25T11:34:10.0120119Z resultfilename       TestResults.xml
2024-04-25T11:34:10.0120965Z testrunnercodeunitid                
2024-04-25T11:34:10.0121166Z 
2024-04-25T11:34:10.0144463Z 
2024-04-25T11:34:10.0153487Z 
2024-04-25T11:34:10.0306918Z True
2024-04-25T11:34:10.0494865Z *** For documentation, please visit   : https://www.alops.be/documentation
2024-04-25T11:34:10.0498443Z 
2024-04-25T11:34:10.2745044Z *** ALOps License:
2024-04-25T11:34:10.2766135Z   * Licensed To: prisma informatik GmbH (Organisation License)
2024-04-25T11:34:10.2770641Z 
2024-04-25T11:34:10.2909281Z *** Importing required PS-Functions
2024-04-25T11:34:10.3384157Z *** Working folder: C:\agent\_work\1795\s
2024-04-25T11:34:10.3391012Z ***
2024-04-25T11:34:10.3397781Z *** Prepare Docker Session
2024-04-25T11:34:10.4325172Z *** Connect Docker Session
2024-04-25T11:34:10.4405384Z *** Initiate Docker Session
2024-04-25T11:34:10.7713224Z *** Set Docker Container ErrorActionPreference = Stop
2024-04-25T11:34:11.1685704Z *** Copy Modules to Docker
2024-04-25T11:34:13.6297825Z *** Setup Docker Session
2024-04-25T11:34:13.6656307Z *** Checking for container-specific Test Assemblies
2024-04-25T11:34:13.6686095Z *** Using container-specific Test Assemblies
2024-04-25T11:34:13.7716392Z *** Import Modules in Docker Session
2024-04-25T11:34:13.9842836Z *** Import UI Client [C:\Run\DevOps\BCAppTest\bin\Microsoft.Dynamics.Framework.UI.Client.dll]
2024-04-25T11:34:14.0038053Z *** Selected module: [C:\Run\DevOps\BCAppTest\bin\Microsoft.Dynamics.Framework.UI.Client.dll]
2024-04-25T11:34:14.0041026Z *** Loading module: [C:\Run\DevOps\BCAppTest\bin\Microsoft.Dynamics.Framework.UI.Client.dll]
2024-04-25T11:34:14.1809675Z *** Import NewtonSoft JSON [C:\Program Files\Microsoft Dynamics NAV\240\Service\Management\Newtonsoft.Json.dll]
2024-04-25T11:34:14.2018951Z *** Import Modules in Docker Session: class_ClientContext
2024-04-25T11:34:14.5401561Z *** Test Context Url: https://9c88fb310b8f/BC/cs?tenant=default&company=CRONUS%20DE
2024-04-25T11:34:14.5408255Z *** Setup BC Credentials in Docker
2024-04-25T11:34:14.6815686Z *** Resolve Docker Credentials
2024-04-25T11:34:14.7259664Z *** Set TCP Keep-Alive
2024-04-25T11:34:14.7499945Z *** Start TestSuite
2024-04-25T11:34:14.7845042Z *** Running TestSuite with authentication [NavUserPassword] with User [admin]
2024-04-25T11:34:14.7868440Z *** Run warm-up with page [130455]
2024-04-25T11:34:14.7891305Z *** Warm-up Client Context
2024-04-25T11:34:18.3643105Z ERROR DIALOG: You must choose a company before you can access the "Global Application User Settings" table.
2024-04-25T11:34:18.8501625Z *** Create Client Context
2024-04-25T11:34:20.3282080Z *** Get Available Tests for suite [DEFAULT] with page [130455]
2024-04-25T11:34:20.5387075Z Show dialog 00000000-0000-0000-0800-0000836bd2d2
2024-04-25T11:34:20.5941680Z Title: Dialog Error
2024-04-25T11:34:20.5956249Z ERROR DIALOG: You must choose a company before you can access the "Global Application User Settings" table.
2024-04-25T11:34:20.8737298Z ##[error]Run-Test-Exception: Cannot open page 130455. You might need to import the test toolkit to the container and/or remove the folder  and retry. You might also have URL or Company name wrong.
2024-04-25T11:34:20.9833298Z *** Get XUnit Test file from [] to [C:\agent\_work\1795\s\]
2024-04-25T11:34:21.1634249Z ##[error]Das Argument kann nicht an den Parameter "Path" gebunden werden, da es NULL ist.
2024-04-25T11:34:21.2055237Z ##[section]Finishing: Run TestSuite
waldo1001 commented 1 month ago

Hm. The eventlog doesn't show anything useful.

Would you be able to send us a repro? A repo & yaml that fails on your end?

waldo1001 commented 4 weeks ago

@DanielGoehler ?

DanielGoehler commented 4 weeks ago

@waldo1001 I haven't been able to create an example that I can share publicly. It is possible to share this privately as a here?

waldo1001 commented 4 weeks ago

Sure!

DanielGoehler commented 3 weeks ago

@waldo1001 I have sent this email.

pri-kise commented 3 weeks ago

Is there any progress to get this resolved in the near future?

This problem occurs in more projects for BC24 versions now. Currenlty the only option is to disable the CI for tests in BC24 projects, but this isn't a real option.

DanielGoehler commented 1 week ago

@waldo1001 By accident, a colleague found the issue. In BC24, there's likely an upgrade/install step that runs without a client context. We've changed the logic (setting Global Application User Settings to DataPerCompany = false), and now it works fine.

waldo1001 commented 1 week ago

@waldo1001 By accident, a colleague found the issue. In BC24, there's likely an upgrade/install step that runs without a client context. We've changed the logic (setting Global Application User Settings to DataPerCompany = false), and now it works fine.

Thanks a lot. Till today, we were still not able to repro it. I'm not sure what you mean with "global application user settings"? 🤔

DanielGoehler commented 1 week ago

@waldo1001 Global Application User Settings is a custom table, but I wasn't aware of this until I saw the Pull Request.

waldo1001 commented 1 week ago

Hm, that makes sense... does it happen to be doing something OnCompanyOpen or something?

DanielGoehler commented 1 week ago

@pri-kise Can you answer this?

waldo1001 commented 1 week ago

@pri-kise Can you answer this?

Wait - @pri-kise and you are the same company?

pri-kise commented 1 week ago

The Global Application User Settings is a custom table (not in the related app, but a dependency). There was a a subscriber for the table "Application User Setting" (System Table). This table has "DataPerCompany=false". This has never been any problem when the code was triggered via UI since there is always a company context. But BC24 added an upgrade (UpgradePerDatabase) where no Company Context is set.

And yes I'm in the same company.

waldo1001 commented 1 week ago

Hm, ok. Thanks for explaining. Now I also understand why the ticket was closed when you (Killian) still had an outstanding question ;-).

Thanks for the info!

DanielGoehler commented 1 week ago

Sorry for the confusion. Next time, I'll include this information.

pri-kise commented 1 week ago

@waldo1001 if we could get the StackTrace (from the event log) of the error then we could have solved that much faster.

waldo1001 commented 1 week ago

@waldo1001 if we could get the StackTrace (from the event log) of the error then we could have solved that much faster.

You can, can't you? https://github.com/HodorNV/ALOps/blob/master/Examples/19_ExportEventLog.yml

DanielGoehler commented 1 week ago

Yes, we did, but the event log wasn't useful. You wrote:

Hm. The eventlog doesn't show anything useful.

Would you be able to send us a repro? A repo & yaml that fails on your end?

waldo1001 commented 1 week ago

Ah, ok - you mean there's no stacktrace in the eventlog .. :-/. I didn't know - sometimes there is a stacktrace, like when you log slow running SQL.. .

Well, may be we should have set up Telemetry from the image, and look into Telemetry.

May be a tip: https://youtu.be/PLRkN2UBhTg?t=4070 In that session, I address the extra possibility to add Telemetry-events on the test-framework. We do that. in that way, you could go to the stacktrace from there .. ?