forked from neo4j-drivers/seabolt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests.ps1
220 lines (193 loc) · 5.28 KB
/
run_tests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
$ErrorActionPreference="Stop"
$BaseDir=$PSScriptRoot
$Password="password"
$Port=7699
$Python="python.exe"
$TestArgs=$args
$ErrorBoltKitNotAvailable=11
$ErrorCompilationFailed=12
$ErrorServerCleanUpFailed=18
$ErrorServerInstallFailed=13
$ErrorServerConfigFailed=14
$ErrorServerStartFailed=15
$ErrorServerStopFailed=16
$ErrorServerConfigurationError=17
$ErrorTestsFailed=199
trap {
Exit 1
}
Function CheckBoltKit()
{
Write-Host "Checking boltkit..."
& $Python -c "import boltkit" *> $null
If ( $LASTEXITCODE -ne 0 )
{
throw @{
Code = $ErrorBoltKitNotAvailable
Message = "FATAL: The boltkit library is not available. Use 'pip install boltkit' to install."
}
}
}
Function Compile()
{
Write-Host "Compiling..."
& cmd.exe /c "$BaseDir\make_debug.cmd" $env:SEABOLT_TOOLCHAIN
if ( $LASTEXITCODE -ne 0 )
{
throw @{
Code = $ErrorCompilationFailed
Message = "FATAL: Compilation failed."
}
}
}
Function Cleanup($Target)
{
try
{
Get-ChildItem -Path $Target -ErrorAction Ignore | Remove-Item -Force -Recurse -ErrorAction Stop
}
catch
{
throw @{
Code = $ErrorServerCleanUpFailed
Message = "FATAL: Server directory cleanup failed."
}
}
}
Function InstallServer($Target, $Version)
{
Write-Host "-- Installing server"
$Server = Invoke-Expression "neoctrl-install $Version $Target"
if ( $LASTEXITCODE -ne 0 )
{
throw @{
Code = $ErrorServerInstallFailed
Message = "FATAL: Server installation failed."
}
}
Write-Host "-- Server installed at $Server"
Write-Host "-- Configuring server to listen on port $Port"
& neoctrl-configure "$Server" dbms.connector.bolt.listen_address=:$Port
if ( $LASTEXITCODE -ne 0 )
{
throw @{
Code = $ErrorServerConfigFailed
Message = "FATAL: Unable to configure server port."
}
}
Write-Host "-- Configuring server to accept IPv6 connections"
& neoctrl-configure "$Server" dbms.connectors.default_listen_address=::
if ( $LASTEXITCODE -ne 0 )
{
throw @{
Code = $ErrorServerConfigFailed
Message = "FATAL: Unable to configure server for IPv6."
}
}
Write-Host "-- Setting initial password"
& neoctrl-set-initial-password "$Password" "$Server"
if ( $LASTEXITCODE -ne 0 )
{
throw @{
Code = $ErrorServerConfigFailed
Message = "FATAL: Unable to set initial password."
}
}
Return $Server
}
Function StartServer($Server)
{
Write-Host "-- Starting server"
$BoltUri = Invoke-Expression "neoctrl-start $Server" | Select-String "^bolt:"
if ( $LASTEXITCODE -ne 0 )
{
throw @{
Code = $ErrorServerStartFailed
Message = "FATAL: Failed to start server."
}
}
Write-Host "-- Server is listening at $BoltUri"
Return $BoltUri
}
Function StopServer($Server)
{
Write-Host "-- Stopping server"
& neoctrl-stop $Server
if ( $LASTEXITCODE -ne 0 )
{
throw @{
Code = $ErrorServerStopFailed
Message = "FATAL: Failed to stop server."
}
}
}
Function RunTests($Version)
{
$CompilationBase = "$Basedir\build-$( $env:SEABOLT_TOOLCHAIN )-debug"
$SeaboltCli = Get-ChildItem -Path $CompilationBase\bin -Filter seabolt-cli.exe -Recurse
$SeaboltTest = Get-ChildItem -Path $CompilationBase\bin -Filter seabolt-test.exe -Recurse
$ServerBase = "$CompilationBase\server"
Cleanup $ServerBase
Write-Host "Testing against Neo4j $Version"
$Server = InstallServer $ServerBase $Version
$BoltUri = StartServer $Server
try
{
Write-Host "-- Checking server"
$env:BOLT_PASSWORD=$Password
$env:BOLT_PORT=$Port
& $SeaboltCli.FullName debug "UNWIND range(1, 10000) AS n RETURN n"
if ( $LASTEXITCODE -ne 0 )
{
throw @{
Code = $ErrorServerConfigurationError
Message = "FATAL: Server is incorrectly configured."
}
}
Write-Host "-- Running tests"
& $SeaboltTest.FullName $TestArgs
if ( $LASTEXITCODE -ne 0 )
{
throw @{
Code = $ErrorTestsFailed
Message = "FATAL: Test execution failed."
}
}
}
finally
{
StopServer $Server
}
}
try
{
$env:NEO4J_CHILD_SCRIPT="1"
CheckBoltKit
Compile
$Neo4jVersion = "-e 3.5"
If (Test-Path "env:NEOCTRLARGS") {
$Neo4jVersion = $env:NEOCTRLARGS
}
RunTests $Neo4jVersion
}
catch
{
$ErrorCode = 1
$ErrorMessage = $_.Exception.Message
If ( $_.TargetObject.Code -and $_.TargetObject.Message )
{
$ErrorCode = $_.TargetObject.Code
$ErrorMessage = $_.TargetObject.Message
}
If ( $env:TEAMCITY_PROJECT_NAME )
{
$CleanedErrorMessage = $ErrorMessage -replace "[^a-zA-Z0-9., ]"
Write-Host "##teamcity[buildProblem description='$($CleanedErrorMessage)' identity='$($ErrorCode)']"
Write-Host "##teamcity[buildStatus status='FAILURE' text='$($CleanedErrorMessage)']"
}
Else
{
Write-Host "$($ErrorMessage) [$($ErrorCode)]"
}
Exit $ErrorCode
}