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

Unable to execute test from VS Code #124

Open
Mesomorf opened this issue Feb 17, 2024 · 11 comments
Open

Unable to execute test from VS Code #124

Mesomorf opened this issue Feb 17, 2024 · 11 comments

Comments

@Mesomorf
Copy link

When trying to execute a test from VS Code, I am getting this error.
Docker is running locally

`PS D:\BC\docker\TransSoft\Apps\Base App - Test> if ($null -eq (Get-Module ALTestRunner)) {Import-Module "c:\Users\Jesper.vscode\extensions\jamespearson.al-test-runner-0.10.1\PowerShell\ALTestRunner.psm1" -DisableNameChecking}
PS D:\BC\docker\TransSoft\Apps\Base App - Test>
PS D:\BC\docker\TransSoft\Apps\Base App - Test> cd "d:\BC\docker\TransSoft\Apps\Base App - Test"
PS D:\BC\docker\TransSoft\Apps\Base App - Test> Invoke-ALTestRunner -Tests Test -ExtensionId "0320f6fa-984c-4dea-88c4-2362f5fa9687" -ExtensionName "Transsoft - Base App (TEST)" -FileName "d:\BC\docker\TransSoft\Apps\Base App - Test\Source\Planning\Plan Line - Syncronize Date & Time (TEST).Codeunit.al" -SelectionStart 16 -LaunchConfig '{"name":"Docker - Sandbox","request":"launch","type":"al","environmentType":"Sandbox","server":"http://SANDBOX23","serverInstance":"BC","authentication":"UserPassword","startupObjectId":130451,"startupObjectType":"Page","breakOnError":"All","launchBrowser":false,"enableLongRunningSqlStatements":true,"enableSqlInformationDebugger":true,"tenant":"default","usePublicURLFromServer":true}' -GetPerformanceProfile
Container SANDBOX23 is not running. Please start the container and retry. Please note that container names are case-sensitive.
At C:\Users\Jesper.vscode\extensions\jamespearson.al-test-runner-0.10.1\PowerShell\Invoke-ALTestRunner.ps1:29 char:9

  •     throw "Container $ContainerName is not running. Please start  ...
    
  •     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : OperationStopped: (Container SANDB...case-sensitive.:String) [], RuntimeException
    • FullyQualifiedErrorId : Container SANDBOX23 is not running. Please start the container and retry. Please note that container names are case-sensitive.

PS D:\BC\docker\TransSoft\Apps\Base App - Test> `

My test app launch.config

{ "version": "0.2.0", "configurations": [ { "name": "Docker - Sandbox", "request": "launch", "type": "al", "environmentType": "Sandbox", "server": "http://SANDBOX23", "serverInstance": "BC", "authentication": "UserPassword", "startupObjectId": 130451, "startupObjectType": "Page", "breakOnError": "All", "launchBrowser": false, "enableLongRunningSqlStatements": true, "enableSqlInformationDebugger": true, "tenant": "default", "usePublicURLFromServer": true } ] }

My test app .altestrunner\config.json

{ "containerResultPath": "", "launchConfigName": "Docker - Sandbox", "securePassword": "", "userName": "", "companyName": "My Company", "testSuiteName": "BASE APP", "vmUserName": "", "vmSecurePassword": "", "remoteContainerName": "", "dockerHost": "", "newPSSessionOptions": "", "testRunnerServiceUrl": "http://SANDBOX23:7048/BC/ODataV4/TestRunner?company=My Company\u0026tenant=default", "codeCoveragePath": ".//.altestrunner//codecoverage.json", "culture": "en-US" }

@jimmymcp
Copy link
Owner

Hi,

Is the container actually running? And then does the name match the server value that you have in launch.json? Docker container names are case sensitive. It is currently checking for SANDBOX23 in all caps.

@Mesomorf
Copy link
Author

Yes the container is running. I can deploy the app in the container using the launch.json from VS code.

@jimmymcp
Copy link
Owner

jimmymcp commented Feb 18, 2024 via email

@Mesomorf
Copy link
Author

I have renamed my docker, to SB, to avoid any spelling errors.
When running docker PS I get the following

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b1bed30d122e mcr.microsoft.com/businesscentral:10.0.20348.2322 "powershell -Command…" 10 minutes ago Up 10 minutes (healthy) 80/tcp, 443/tcp, 1433/tcp, 7045-7049/tcp, 7083/tcp, 8080/tcp SB

But I still get the error

`PS D:\BC\docker\TransSoft\Apps\Base App - Test> if ($null -eq (Get-Module ALTestRunner)) {Import-Module "c:\Users\Jesper.vscode\extensions\jamespearson.al-test-runner-0.10.1\PowerShell\ALTestRunner.psm1" -DisableNameChecking}
PS D:\BC\docker\TransSoft\Apps\Base App - Test>
PS D:\BC\docker\TransSoft\Apps\Base App - Test> cd "d:\BC\docker\TransSoft\Apps\Base App - Test"
PS D:\BC\docker\TransSoft\Apps\Base App - Test> Invoke-ALTestRunner -Tests Test -ExtensionId "0320f6fa-984c-4dea-88c4-2362f5fa9687" -ExtensionName "Transsoft - Base App (TEST)" -FileName "d:\BC\docker\TransSoft\Apps\Base App - Test\Source\Foundation\Address (TEST).Codeunit.al" -SelectionStart 12 -LaunchConfig '{"name":"Docker - Sandbox","request":"launch","type":"al","environmentType":"Sandbox","server":"http://SB","serverInstance":"BC","authentication":"UserPassword","startupObjectId":130451,"startupObjectType":"Page","breakOnError":"All","launchBrowser":false,"enableLongRunningSqlStatements":true,"enableSqlInformationDebugger":true,"tenant":"default","usePublicURLFromServer":true}' -GetPerformanceProfile
Container SB is not running. Please start the container and retry. Please note that container names are case-sensitive.
At C:\Users\Jesper.vscode\extensions\jamespearson.al-test-runner-0.10.1\PowerShell\Invoke-ALTestRunner.ps1:29 char:9

  •     throw "Container $ContainerName is not running. Please start  ...
    
  •     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : OperationStopped: (Container SB is...case-sensitive.:String) [], RuntimeException
    • FullyQualifiedErrorId : Container SB is not running. Please start the container and retry. Please note that container names are case-sensitive.`

@jimmymcp
Copy link
Owner

The Get-ContainerIsRunning function must be returning false. Try running the content of that function directly in the terminal and see what the result is:

$StatusJson = docker inspect $ContainerName
$StatusJson = [String]::Join([Environment]::NewLine, $StatusJson)
$Status = ConvertFrom-Json $StatusJson

if ($PSVersionTable.PSVersion.Major -ge 7) {
    return $Status.State.Running
}
elseif ($Status.Get(0).State.Running -eq 'True') {
    return $true
}

If that returns false then check the the Status and StatusJson variables, see what is being returned by docker inspect.

@Mesomorf
Copy link
Author

This returns true

`PS C:\Windows\system32> $ContainerName = 'SANDBOX23'

PS C:\Windows\system32> $StatusJson = docker inspect $ContainerName
$StatusJson = [String]::Join([Environment]::NewLine, $StatusJson)
$Status = ConvertFrom-Json $StatusJson

if ($PSVersionTable.PSVersion.Major -ge 7) {
return $Status.State.Running
}
elseif ($Status.Get(0).State.Running -eq 'True') {
return $true
}

True`

@navdotnetreqs
Copy link

navdotnetreqs commented May 7, 2024

Same issue here, unable to use the extension due to weird errors like this.
When I try running a test from VS Code, I get:

Importing module bccontainerhelper
BcContainerHelper version 6.0.17
WinRM service is not running, will not try to use WinRM sessions
BC.HelperFunctions emits usage statistics telemetry to Microsoft
Running on Windows, PowerShell 5.1.19041.4291
Container bcserver is not running. Please start the container and retry. Please note that container names are case-sensitive.
At C:\Users\j\.vscode-insiders\extensions\jamespearson.al-test-runner-0.11.1\PowerShell\Invoke-ALTestRunner.ps1:29 char:9
+         throw "Container $ContainerName is not running. Please start  ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Container bcser...case-sensitive.:String) [], RuntimeException
    + FullyQualifiedErrorId : Container bcserver is not running. Please start the container and retry. Please note that container names are case-sensitive

However, when I run the same function, copied from the terminal window, in Powershell ISE, I get:

Invoke-ALTestRunner -Tests Test -ExtensionId "1a3c5c6b-c823-4fea-8f80-6ebf222ef7b0" -ExtensionName ...

Importing module bccontainerhelper
BcContainerHelper version 6.0.17
WinRM service is not running, will not try to use WinRM sessions
BC.HelperFunctions emits usage statistics telemetry to Microsoft
Running on Windows, PowerShell 5.1.19041.4291
Running tests on bcserver, company CRONUS FI, tenant default, codeunit 80100, function TestOnInstallLogic, extension FinvoiceTests, test runner 130450, culture en-US
WARNING: TaskScheduler is running in the container, this can lead to test failures. Specify -EnableTaskScheduler:$false to disable Task Scheduler.

Get-ContainerIsRunning bcserver
returns FALSE when run from vs code's terminal, and true when run from windows powershell ise.

If I run this from "Windows Powershell" (not "ISE") the commands also fail ..

>>     $jsonContent = Get-Content -Path "C:\temp\ps.txt" -Raw -Encoding UTF8
>>     $jsonObject = $jsonContent | ConvertFrom-Json
>> } catch {
>>     Write-Host "Error: $_"
>>     $_.Exception | Format-List * -Force
>>     $_.Exception.InnerException | Format-List * -Force
>> }
>>
Error: Invalid JSON primitive: failed.


Message        : Invalid JSON primitive: failed.
ParamName      :
Data           : {}
InnerException :
TargetSite     : System.Object DeserializePrimitiveObject()
StackTrace     :    at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()
                    at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)
                    at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)
                    at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)
                    at Microsoft.PowerShell.Commands.JsonObject.ConvertFromJson(String input, ErrorRecord& error)
                    at Microsoft.PowerShell.Commands.ConvertFromJsonCommand.ConvertFromJsonHelper(String input)
                    at System.Management.Automation.CommandProcessorBase.Complete()
HelpLink       :
Source         : System.Web.Extensions
HResult        : -2147024809

I figured out that the JSON "Windows Powershell" outputs contains this line upfront (breaking the json-handling):
"failed to get console mode for stdout: The handle is invalid."

@navdotnetreqs
Copy link

I actually seem to have fixed this particular issues. If I change line Get-ContainerIsRunning.ps1 to:
$StatusJson = docker inspect $ContainerName 2>&1

from
$StatusJson = docker inspect $ContainerName

The json is correctly parsed.

@navdotnetreqs
Copy link

And I assume we get the same issue in all the other powershell-files as well, because now ..

At C:\Program Files\WindowsPowerShell\Modules\bccontainerhelper\6.0.17\ContainerInfo\Get-NavContainerNavVersion.ps1:20 char:55
+ ...    $inspect = docker inspect $containerOrImageName | ConvertFrom-Json
+                                                          ~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [ConvertFrom-Json], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand

@jimmymcp
Copy link
Owner

jimmymcp commented May 7, 2024

I actually seem to have fixed this particular issues. If I change line Get-ContainerIsRunning.ps1 to: $StatusJson = docker inspect $ContainerName 2>&1

from $StatusJson = docker inspect $ContainerName

The json is correctly parsed.

thanks for the update, what does that do? Would you be able to create a pull request with the changes?

@navdotnetreqs
Copy link

Hi @jimmymcp ,
I just confirmed that docker has fixed the issue in newer versions (see linked issue). After updating to newest docker running tests work fine - even without that modification. The mod only directed the error output away.

Trying to debug tests results in an internal error (500), but that's a separate issue and maybe not even related to AL Test Runner (same thing if I try from Powershell). :)

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

No branches or pull requests

3 participants