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

Add simple integration test, with an LSP client PowerShell module #944

Merged
merged 47 commits into from
May 17, 2019

Conversation

rjmholt
Copy link
Contributor

@rjmholt rjmholt commented Apr 22, 2019

I've written a small named-pipe-based LSP client in PowerShell, partly to understand PSES better and partly to provide an automated way for us to determine if PSES is loading and working properly with PowerShell.

There are two tests with this now:

  • A startup/initialize/response message where we start the process, send an initialize message and check the response
  • A shutdown message test, where we check the process understands a shutdown notification

@PowerShell PowerShell deleted a comment Apr 22, 2019
@PowerShell PowerShell deleted a comment Apr 22, 2019
@PowerShell PowerShell deleted a comment Apr 22, 2019
@PowerShell PowerShell deleted a comment Apr 22, 2019
@PowerShell PowerShell deleted a comment Apr 22, 2019
@PowerShell PowerShell deleted a comment Apr 22, 2019
@PowerShell PowerShell deleted a comment Apr 22, 2019
@PowerShell PowerShell deleted a comment Apr 22, 2019
@PowerShell PowerShell deleted a comment Apr 22, 2019
@PowerShell PowerShell deleted a comment Apr 22, 2019
@PowerShell PowerShell deleted a comment Apr 22, 2019
@PowerShell PowerShell deleted a comment Apr 22, 2019
@PowerShell PowerShell deleted a comment Apr 22, 2019
@PowerShell PowerShell deleted a comment Apr 22, 2019
@PowerShell PowerShell deleted a comment Apr 22, 2019
@PowerShell PowerShell deleted a comment Apr 23, 2019
@PowerShell PowerShell deleted a comment Apr 23, 2019
@PowerShell PowerShell deleted a comment Apr 23, 2019
@PowerShell PowerShell deleted a comment Apr 23, 2019
@PowerShell PowerShell deleted a comment Apr 23, 2019
@PowerShell PowerShell deleted a comment May 14, 2019
@PowerShell PowerShell deleted a comment May 14, 2019
@PowerShell PowerShell deleted a comment May 14, 2019
@PowerShell PowerShell deleted a comment May 14, 2019
@TylerLeonhardt
Copy link
Member

These tests saved us 🎉

@rjmholt
Copy link
Contributor Author

rjmholt commented May 15, 2019

It works again!

@PowerShell PowerShell deleted a comment May 15, 2019
@PowerShell PowerShell deleted a comment May 15, 2019
@PowerShell PowerShell deleted a comment May 15, 2019
@PowerShell PowerShell deleted a comment May 15, 2019
@PowerShell PowerShell deleted a comment May 15, 2019
@PowerShell PowerShell deleted a comment May 15, 2019
@PowerShell PowerShell deleted a comment May 15, 2019
@PowerShell PowerShell deleted a comment May 15, 2019
@PowerShell PowerShell deleted a comment May 15, 2019
@PowerShell PowerShell deleted a comment May 15, 2019
@PowerShell PowerShell deleted a comment May 15, 2019
@PowerShell PowerShell deleted a comment May 15, 2019
ReportLogErrors -LogPath $psesServer.LogPath -FromIndex ([ref]$logIdx)
}

# This test MUST be last
Copy link
Member

@TylerLeonhardt TylerLeonhardt May 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this is the right approach. Maybe it should be 2 Context's:

  1. "Message handling"
  2. "Startup and shutdown"

So the tests would be structured like this:

Describe "Loading and running PowerShellEditorServices" {
    BeforeAll {
        Import-Module -Force "$PSScriptRoot/../../module/PowerShellEditorServices"
        Import-Module -Force "$PSScriptRoot/../../tools/PsesPsClient/out/PsesPsClient"
        Import-Module -Force "$PSScriptRoot/../../tools/PsesLogAnalyzer"

        $logIdx = 0
    }
    Context "Startup and shutdown" {
        It "Can start up and shutdown" {
            # Start up
            $psesServer = Start-PsesServer
            $client = Connect-PsesServer -PipeName $psesServer.SessionDetails.languageServicePipeName

            # Shutdown
            $request = Send-LspShutdownRequest -Client $client
            $response = Get-LspResponse -Client $client -Id $request.Id
            $response.Id | Should -BeExactly $request.Id
            $response.Result | Should -BeNull
            # TODO: The server seems to stay up waiting for the debug connection
            # $psesServer.PsesProcess.HasExited | Should -BeTrue
           
            try
            {
                $psesServer.PsesProcess.Kill()
            }
            finally
            {
                try
                {
                    $psesServer.PsesProcess.Dispose()
                }
                finally
                {
                    $client.Dispose()
                }
            }

            ReportLogErrors -LogPath $psesServer.LogPath -FromIndex ([ref]$logIdx)
        }
    }

    Context "LSP messages" {
        BeforeAll {
            # Start up
            $psesServer = Start-PsesServer
            $client = Connect-PsesServer -PipeName $psesServer.SessionDetails.languageServicePipeName
        }
        AfterAll {
            try
            {
                $psesServer.PsesProcess.Kill()
            }
            finally
            {
                try
                {
                    $psesServer.PsesProcess.Dispose()
                }
                finally
                {
                    $client.Dispose()
                }
            }
        }
        It "Can send initialize request" {
            $request = Send-LspInitializeRequest -Client $client
            $response = Get-LspResponse -Client $client -Id $request.Id
            $response.Id | Should -BeExactly $request.Id

            ReportLogErrors -LogPath $psesServer.LogPath -FromIndex ([ref]$logIdx)
        }
        #
        # As time goes on we add more It's here for the other messages
        #
    }
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That way the order doesn't matter and we can easily add new tests for other messages.

For the future:
I think the Send-LspInitializeRequest will actually probably need to be moved to the BeforeAll eventually once we add other messages that depend on that one having gone through.

We'll get there. Gotta figure out which messages depend on what and align the tests as much as possible to that back and forth.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I don't think there's any particularly obvious approach available at the moment. I think given that we're not planning impending development on this module that we should merge what we have since it works and is less code and then continue as is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely don't disagree with you though -- "unit" testing is very bad at sequential logic with dependent states.

I think we should refactor as you say, but will defer that to another PR.

Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rjmholt rjmholt merged commit 14ddd0f into PowerShell:master May 17, 2019
@rjmholt rjmholt deleted the integration-tools branch December 11, 2019 21:42
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

Successfully merging this pull request may close these issues.

3 participants