HodorNV / ALOps

ALOps
59 stars 24 forks source link

Problem with running tests because of task scheduler(?) #560

Closed NAVFreak closed 2 years ago

NAVFreak commented 2 years ago

Describe the bug I can't run a certain test scenario in my ALOps pipeline. After googling the error I found this dialoge with waldo and Freddy which seems to have the same error and it is because the task scheduler is running.

My error:

Stack trace
"Library - Sales"(CodeUnit 130509).CreateSalesLineWithShipmentDate line 23 - Tests-TestLibraries by Microsoft
"Library - Sales"(CodeUnit 130509).CreateSalesLine line 2 - Tests-TestLibraries by Microsoft
"Library - Sales"(CodeUnit 130509).CreateSalesOrder line 8 - Tests-TestLibraries by Microsoft
"NBAWMS Helper Functions"(CodeUnit 99003).CreateSalesOrder line 9 - Test Navet WMS by Navet AB
NBAWMSSalesPartOrderTest(CodeUnit 99000).ReleasePartOrder line 9 - Test Navet WMS by Navet AB
"Test Runner - Mgt"(CodeUnit 130454).RunTests line 18 - Test Runner by Microsoft
"Test Runner - Isol. Codeunit"(CodeUnit 130450).OnRun(Trigger) line 4 - Test Runner by Microsoft
"Test Suite Mgt."(CodeUnit 130456).RunTests line 2 - Test Runner by Microsoft
"Test Suite Mgt."(CodeUnit 130456).RunSelectedTests line 35 - Test Runner by Microsoft
"Command Line Test Tool"(Page 130455)."RunSelectedTests - OnAction"(Trigger) line 7 - Test Runner by Microsoft
Showing 40 filtered items.

So now I try to disable the task scheduler in the pipeline. I found out there is an option which I think I can use for this.

- task: ALOpsDockerStart@1
  displayName: 'ALOPS - Start Docker Container' # No need to provide any details - it will get the details from previous step
  inputs:
    taskscheduler: false

Is this correct to inactivate the taskscheduler?

the used yaml If it looks weird it's because I have pasted most of it from different template files

- task: ALOpsAgentMaintenance@1
  inputs:
    removeoldtasks: true
    removeunusedcontainers: true
    pruneimagesdayscreated: $(Pipeline-pruneimagesdayscreated) # Force docker image pruning based on creation date (x days).
    removebcartifacts: true
    daysunused: $(Pipeline-daysunused)

- task: ALOpsDockerCreate@1
  displayName: 'ALOPS - Create Docker Image' # It will reuse the image if already exists, or build one if it doesn't.
  inputs:
    artifacttype: ${{ parameters.artifacttype }} #Sandbox
    artifactversion: ${{ parameters.artifactversion }} #''
    artifactcountry: ${{ parameters.artifactcountry }} #SE                     
    versionselect: ${{ parameters.VersionSelect }}  # Latest

- task: ALOpsDockerStart@1
  displayName: 'ALOPS - Start Docker Container' # No need to provide any details - it will get the details from previous step
  inputs:
    taskscheduler: false

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

- task: ALOpsLicenseImport@1
  displayName: 'ALOPS - License Import'
  inputs:
    usedocker: true
    license_path: ${{ parameters.LicencePath }}  

- task: ALOpsAppPublish@1
  displayName: 'ALOPS - Install AL TestTool' # install necessary dependent apps for testability
  inputs:
    usedocker: ${{ parameters.usedocker }} #True
    installaltesttool: ${{ parameters.installaltesttool }} #True
    skip_verification: ${{ parameters.skip_verification }} #True
    install_al_app_names: |
     Permissions Mock
     Tests-TestLibraries
     System Application Test
     System Application Test Library
     Any
     Library Assert
     Test Runner

- task: ALOpsAppPublish@1
    displayName: 'BatchPublish - ALOpsAppPublish@1'
    inputs:
      usedocker: true
      skip_verification: true    
      batch_publish_folder: '$(System.ArtifactsDirectory)\Dependencies'

  - template: ./DevOps/Compile_And_Publish.yml@Templates
    parameters:
      app_name: 'WMS APP'                                  
      bc_app_version: '17.0.[yyyyWW].*'                    
      app_file_suffix: '_APP'
      failed_on_warnings: false
      targetproject: 'App/app.json'

  - template: ./DevOps/Compile_And_Publish.yml@Templates
    parameters:
      app_name: 'Test APP'
      bc_app_version: '1.0.[yyyyWW].*'
      app_file_suffix: '_TEST'
      failed_on_warnings: false
      targetproject: 'test/app.json'

  - task: ALOpsAppTest@1
    displayName: 'ALOPS - Run TestSuite'
    inputs:
      usedocker: true
      import_action: "Skip"
      import_testtoolkit: false
      testpage: '130455'
      testsuite: 'DEFAULT'
      failed_test_action: Error   #Warning/Error
    continueOnError: false    

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

the output Also the complete output is necessary for us to see what is going on. Also use backtics: Out from ALOPS Start Docker and ALOPS Run test suite

sql_backup_file                                                                            
encryption_key                                                                             
taskscheduler               false                                                          

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

*** ALOps License:
  * Licensed To: ***** AB (Collection/Organization License)

*** Overrule 'EnableTaskScheduler': FALSE
"docker" create --env accept_eula=Y --env accept_outdated=Y --restart no --label TFSBuild=Extension-WMS_8473 myimage:sandbox-***0.4.443***3.45366-se-***0.0.***7763.3***87dev-ltsc***0***9
*** Checking for Assemblies in App
"docker" start ***bcd5c8d48e9da68***67***b3***4***9f***64a7ec5c6cf5af5587b379e4dad3b3c74c5a
*** Container Started: ***bcd5c8d48e9da68***67***b3***4***9f***64a7ec5c6cf5af5587b379e4dad3b3c74c5a
*** Container Labels:

*** Docker Start OK.
*** Cleanup VSTS Environment: True
Async Command Start: Add Build Tag
Build '8473' has following tags now: myimage-sandbox-***0.4.443***3.45366-se-***0.0.***7763.3***87dev-ltsc***0***9
Async Command End: Add Build Tag
Async Command Start: Add Build Tag
Build '8473' has following tags now: BC.Platform.***0.0.44***66.45***40, myimage-sandbox-***0.4.443***3.45366-se-***0.0.***7763.3***87dev-ltsc***0***9
Async Command End: Add Build Tag
Async Command Start: Add Build Tag
Build '8473' has following tags now: BC.Platform.***0.0.44***66.45***40, myimage-sandbox-***0.4.443***3.45366-se-***0.0.***7763.3***87dev-ltsc***0***9, BC.Version.***0.4.443***3.45366
Async Command End: Add Build Tag
Finishing: ALOPS - Start Docker Container

Testing:
2022-08-23T08:16:25.7783240Z ##[section]Starting: ALOPS - Run TestSuite
2022-08-23T08:16:25.8008477Z ==============================================================================
2022-08-23T08:16:25.8009029Z Task         : ALOps App Test
2022-08-23T08:16:25.8009395Z Description  : Run AL-TestSuite for Business Central
2022-08-23T08:16:25.8009824Z Version      : ***.45***.3***7
2022-08-23T08:16:25.8010134Z Author       : Hodor
2022-08-23T08:16:25.8010527Z Help         : Run Business Central Test-Suite and collect results.
2022-08-23T08:16:25.8011049Z ==============================================================================
2022-08-23T08:16:28.6152433Z *** Validate configuration
2022-08-23T08:16:29.0146290Z *** Task Inputs:
2022-08-23T08:16:29.0147648Z 
2022-08-23T08:16:29.0302694Z name                           value
2022-08-23T08:16:29.0304619Z ----                           -----
2022-08-23T08:16:29.0305130Z usedocker                       True
2022-08-23T08:16:29.0306162Z fixed_tag                           
2022-08-23T08:16:29.0307447Z nav_serverinstance             BC***40
2022-08-23T08:16:29.0307980Z tenant                       default
2022-08-23T08:16:29.0308854Z companyname                         
2022-08-23T08:16:29.0309640Z profile                             
2022-08-23T08:16:29.0311017Z bc_username                         
2022-08-23T08:16:29.0313504Z bc_password                         
2022-08-23T08:16:29.0317096Z bc_authentication    NavUserPassword
2022-08-23T08:16:29.0318151Z bc_webclient_url                    
2022-08-23T08:16:29.0319593Z testfilter                          
2022-08-23T08:16:29.0321034Z disabledtests                       
2022-08-23T08:16:29.0322439Z show_available_tests            True
2022-08-23T08:16:29.0323724Z import_testtoolkit             False
2022-08-23T08:16:29.0325148Z import_action                   Skip
2022-08-23T08:16:29.0326632Z testpage                      ***30455
2022-08-23T08:16:29.0328783Z testsuite                    DEFAULT
2022-08-23T08:16:29.0330917Z extensionid                         
2022-08-23T08:16:29.0333344Z installaltesttool              False
2022-08-23T08:16:29.0334473Z failed_test_action             Error
2022-08-23T08:16:29.0335848Z override_finsql_path                
2022-08-23T08:16:29.0338381Z resultfilename       TestResults.xml
2022-08-23T08:16:29.0341141Z testrunnercodeunitid                
2022-08-23T08:16:29.0341454Z 
2022-08-23T08:16:29.0369894Z 
2022-08-23T08:16:29.0383371Z 
2022-08-23T08:16:29.0590669Z *** For documentation, please visit   : https://www.alops.be/documentation
2022-08-23T08:16:29.0606050Z 
2022-08-23T08:16:29.3498005Z *** ALOps License:
2022-08-23T08:16:29.3528308Z   * Licensed To: ***** AB (Collection/Organization License)
2022-08-23T08:16:29.3534534Z 
2022-08-23T08:16:29.3726749Z *** Importing required PS-Functions
2022-08-23T08:16:29.6493632Z *** Working folder: c:\vsts-agent-win-x64-***.***0***.0\_work\3\s
2022-08-23T08:16:29.6506361Z ***
2022-08-23T08:16:29.6518670Z *** Prepare Docker Session
2022-08-23T08:16:29.8211717Z *** Connect Docker Session
2022-08-23T08:16:29.8313883Z *** Initiate Docker Session
2022-08-23T08:16:30.1019399Z *** Set Docker Container ErrorActionPreference = Stop
2022-08-23T08:16:30.4581013Z *** Copy Modules to Docker
2022-08-23T08:16:34.7998689Z *** Setup Docker Session
2022-08-23T08:16:34.8387247Z *** Checking for container-specific Test Assemblies
2022-08-23T08:16:34.8408247Z *** Using container-specific Test Assemblies
2022-08-23T08:16:34.8706176Z *** Import Modules in Docker Session
2022-08-23T08:16:35.1465016Z *** Import UI Client [C:\Run\DevOps\BCAppTest\bin\Microsoft.Dynamics.Framework.UI.Client.dll]
2022-08-23T08:16:35.1495003Z VERBOSE: Loading module from path 'C:\Run\DevOps\BCAppTest\bin\Microsoft.Dynamics.Framework.UI.Client.dll'.
2022-08-23T08:16:35.3369355Z *** Import NewtonSoft JSON [C:\Program Files\Microsoft Dynamics NAV\***00\Service\Newtonsoft.Json.dll]
2022-08-23T08:16:35.3576936Z *** Import Modules in Docker Session: class_ClientContext
2022-08-23T08:16:38.4892451Z *** Test Context Url: https://***bcd5c8d48e9/BC/cs?tenant=default
2022-08-23T08:16:38.4904580Z *** Setup BC Credentials in Docker
2022-08-23T08:16:38.6772416Z *** Resolve Docker Credentials
2022-08-23T08:16:38.6855448Z *** Set TCP Keep-Alive
2022-08-23T08:16:38.7041707Z *** Start TestSuite
2022-08-23T08:16:38.7752273Z *** Running TestSuite with authentication [NavUserPassword] with User [admin]
2022-08-23T08:16:38.7775656Z *** Run warm-up with page [***30455]
2022-08-23T08:16:38.7796079Z *** Warm-up Client Context
2022-08-23T08:16:59.2579335Z *** Create Client Context
2022-08-23T08:17:00.7020606Z *** Get Available Tests for suite [DEFAULT] with page [***30455]
2022-08-23T08:17:01.7256347Z Show form 000***fd97-0000-000***-0c00-0000836bd***d***
2022-08-23T08:17:01.8984972Z Title: Command Line Test Tool Edit - Command Line Test Tool - DEFAULT
2022-08-23T08:17:02.0047899Z *** Set [CurrentSuiteName] => [DEFAULT]
2022-08-23T08:17:04.3382100Z [
2022-08-23T08:17:04.3383763Z     {
2022-08-23T08:17:04.3384216Z         "Tests":  [
2022-08-23T08:17:04.3385679Z                       "ReleasePartOrder",
2022-08-23T08:17:04.3386689Z                       "ReleaseSecondPartOrder"
2022-08-23T08:17:04.3387636Z                   ],
2022-08-23T08:17:04.3388146Z         "Name":  "NBAWMSSalesPartOrderTest",
2022-08-23T08:17:04.3388629Z         "Id":  "99000"
2022-08-23T08:17:04.3389075Z     },
2022-08-23T08:17:04.3390552Z     {...
2022-08-23T08:17:04.3421438Z     }
2022-08-23T08:17:04.3421794Z ]
2022-08-23T08:17:04.3422456Z *** Run Available Tests for suite [DEFAULT] with page [***30455]
2022-08-23T08:17:04.4130859Z *** Connect TestClient with page [***30455]
2022-08-23T08:17:04.5210644Z Show form 000***fd97-0000-000***-0c00-0000836bd***d***
2022-08-23T08:17:04.5390048Z Title: Command Line Test Tool Edit - Command Line Test Tool - DEFAULT
2022-08-23T08:17:27.9168840Z   Codeunit 99000 NBAWMSSalesPartOrderTest Failure (***.354 seconds)
2022-08-23T08:17:27.9645398Z     Testfunction ReleasePartOrder Failure (***6.896 seconds)
2022-08-23T08:17:46.6985624Z   Codeunit 99004 NBAWMSPurchaseOrderReceiveTest Success (***8.7***4 seconds)
2022-08-23T08:17:55.9190048Z   Codeunit 99005 NBAWMSSalesOrderDeliverTest Success (9.***73 seconds)
2022-08-23T08:18:00.6488677Z   Codeunit 99006 NBAWMSSalesRetOrderReceiveTest Success (4.485 seconds)
2022-08-23T08:18:09.5274862Z   Codeunit 99007 NBAWMSPurchaseRetOrderDeliver Success (8.863 seconds)
2022-08-23T08:18:14.2402436Z   Codeunit 99008 NBAWMS Stock Report Test Success (4.476 seconds)
2022-08-23T08:18:14.4747845Z False
2022-08-23T08:18:14.4797235Z *** XUnit Test results: c:\Run\DevOps\TestResults.xml
2022-08-23T08:18:14.4880232Z <?xml version="***.0" encoding="UTF-8"?>
2022-08-23T08:18:14.4883452Z <assemblies>
2022-08-23T08:18:14.4884595Z   <assembly name="99000 NBAWMSSalesPartOrderTest" test-framework="PS Test Runner" run-date="***0***-08-***3" run-time="08:***7:05" total="***" passed="***" failed="***" skipped="0" time="***0.3***">
2022-08-23T08:18:14.4885901Z     <collection name="NBAWMSSalesPartOrderTest" total="***" passed="***" failed="***" skipped="0" time="***0.3***" Skipped="0">
2022-08-23T08:18:14.4886931Z       <test name="NBAWMSSalesPartOrderTest:ReleasePartOrder" method="ReleasePartOrder" time="***6.896" result="Fail">
2022-08-23T08:18:14.4887648Z         <failure>
2022-08-23T08:18:14.4889114Z           <message>We could not update the data right now.\Please try again later.\\Technical details:\A record in table Sales Line was locked for use in another session. Administrators can see current locks on the Database Locks page or use telemetry. (Snapshot ID: Failed to retrieve relevant parameter)</message>
2022-08-23T08:18:14.4890745Z           <stack-trace>"Library - Sales"(CodeUnit ***30509).CreateSalesLineWithShipmentDate line ***3 - Tests-TestLibraries by Microsoft
2022-08-23T08:18:14.4891760Z "Library - Sales"(CodeUnit ***30509).CreateSalesLine line *** - Tests-TestLibraries by Microsoft
2022-08-23T08:18:14.4892775Z "Library - Sales"(CodeUnit ***30509).CreateSalesOrder line 8 - Tests-TestLibraries by Microsoft
2022-08-23T08:18:14.4894789Z "NBAWMS Helper Functions"(CodeUnit 99003).CreateSalesOrder line 9 - Test Navet WMS by Navet AB
2022-08-23T08:18:14.4895623Z NBAWMSSalesPartOrderTest(CodeUnit 99000).ReleasePartOrder line 9 - Test Navet WMS by Navet AB
2022-08-23T08:18:14.4896508Z "Test Runner - Mgt"(CodeUnit ***30454).RunTests line ***8 - Test Runner by Microsoft
2022-08-23T08:18:14.4897211Z "Test Runner - Isol. Codeunit"(CodeUnit ***30450).OnRun(Trigger) line 4 - Test Runner by Microsoft
2022-08-23T08:18:14.4899785Z "Test Suite Mgt."(CodeUnit ***30456).RunTests line *** - Test Runner by Microsoft
2022-08-23T08:18:14.4901072Z "Test Suite Mgt."(CodeUnit ***30456).RunSelectedTests line 35 - Test Runner by Microsoft
2022-08-23T08:18:14.4902546Z "Command Line Test Tool"(Page ***30455)."RunSelectedTests - OnAction"(Trigger) line 7 - Test Runner by Microsoft</stack-trace>
2022-08-23T08:18:14.4903750Z         </failure>
2022-08-23T08:18:14.4905106Z       </test>
2022-08-23T08:18:14.4905930Z       <test name="NBAWMSSalesPartOrderTest:ReleaseSecondPartOrder" method="ReleaseSecondPartOrder" time="3.4***4" result="Pass" />
2022-08-23T08:18:14.4906936Z     </collection>
2022-08-23T08:18:14.4907292Z   </assembly>
2022-08-23T08:18:14.4951937Z   ....
2022-08-23T08:18:14.4952175Z </assemblies>
2022-08-23T08:18:14.4952454Z 
2022-08-23T08:18:14.4974349Z *** Get XUnit Test file from [c:\Run\DevOps\TestResults.xml] to [c:\vsts-agent-win-x64-***.***0***.0\_work\3\s\TestResults.xml]
2022-08-23T08:18:14.8060756Z 
2022-08-23T08:18:14.8077308Z *** Disconnect Docker session.
2022-08-23T08:18:14.8119430Z *** Docker session removed.
2022-08-23T08:18:14.8352158Z ##[warning]NBAWMSSalesPartOrderTest:ReleasePartOrder: We could not update the data right now.\Please try again later.\\Technical details:\A record in table Sales Line was locked for use in another session. Administrators can see current locks on the Database Locks page or use telemetry. (Snapshot ID: Failed to retrieve relevant parameter)
2022-08-23T08:18:14.8376464Z ##[error]*** Running Tests failed.
2022-08-23T08:18:14.8499470Z Id Name   ComputerName                                                     ComputerType State  ConfigurationName Availa
2022-08-23T08:18:14.8500140Z                                                                                                                  bility
2022-08-23T08:18:14.8511113Z -- ----   ------------                                                     ------------ -----  ----------------- ------
2022-08-23T08:18:14.8520809Z  *** WinRM*** ***bcd5c8d48e9da68***67***b3***4***9f***64a7ec5c6cf5af5587b379e4dad3b3c74c5a Container    Opened                   ...ble
2022-08-23T08:18:14.8521385Z 
2022-08-23T08:18:14.8521529Z 
2022-08-23T08:18:14.8972632Z ##[section]Finishing: ALOPS - Run TestSuite

Expected behavior I expect the task scheduler to be inactivated to see if this is the reason to my problem. If you have any other suggestion please suggest them.

waldo1001 commented 2 years ago

Since you disable the taskscheduler, I think it's cause by something else, like background sessions (startsession) that was started during a testrun.. .

NAVFreak commented 2 years ago

I have searched through my entire workspace and there is no startsession nowhere or other background jobs. I'm not sure that the taskscheduler is inactive. The only thing i see is:

*** Overrule 'EnableTaskScheduler': TRUE
"docker" create --env accept_eula=Y --env accept_outdated=Y --restart no --label TFSBuild=Order Nordic_8580 myimage:sandbox-***0.4.443***3.45688-se-***0.0.***7763.3***87dev-ltsc***0***9

Is there a way to make sure it is not loaded?

The most anoying is that this is happening to me in several pipelines. The only workaround solutions that I have found is to rename the testobject in some pipelines and in some it doesn't work. This stops my entire pipeline cause of failing tests

waldo1001 commented 2 years ago

I think we found it - i didn't notice it, but the developer pointed me to the wrong usage of the "taskscheduler" input in the yaml:

image

So it's either "keep", "enable" or "disable".

Can you try that?

waldo1001 commented 2 years ago

Tip: use the DevOps pipeline editor: it has intellisense ;-)

NAVFreak commented 2 years ago

It worked! 🥳 Yeah I have definately made a note to myself to start use intellisense in the devops pipeline editor. That could have saved me a lot of hours of googling if I had used it earlier 🙈