Skip to content

Commit 2e742de

Browse files
authored
Merge pull request #13 from volt-test/release/0.1.1
Release/0.1.1
2 parents 42591b8 + 993c656 commit 2e742de

File tree

6 files changed

+38
-47
lines changed

6 files changed

+38
-47
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "volt-test/php-sdk",
33
"description": "Volt Test PHP SDK - A performance testing tool for PHP applications",
44
"type": "library",
5-
"version": "0.1.0",
5+
"version": "0.1.1",
66
"keywords": [
77
"volt-test",
88
"php-sdk",

src/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public function setTarget(string $idleTimeout = '30s'): self
8888
throw new VoltTestException('Invalid idle timeout format. Use <number>[s|m|h]');
8989
}
9090
$this->target['idle_timeout'] = $idleTimeout;
91+
9192
return $this;
9293
}
9394

src/Platform.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Platform
66
{
77
private const BINARY_NAME = 'volt-test';
88

9-
private const CURRENT_VERSION = 'v0.0.1-beta';
9+
private const ENGINE_CURRENT_VERSION = 'v0.0.1';
1010
private const BASE_DOWNLOAD_URL = 'https://github.com/volt-test/binaries/releases/download';
1111
private const SUPPORTED_PLATFORMS = [
1212
'linux-amd64' => 'volt-test-linux-amd64',
@@ -67,7 +67,7 @@ private static function getBinaryDir(): string
6767

6868
private static function getCurrentVersion(): string
6969
{
70-
return self::CURRENT_VERSION;
70+
return self::ENGINE_CURRENT_VERSION;
7171
}
7272

7373
private static function detectPlatform($testing = false): string
@@ -99,7 +99,7 @@ public static function installBinary($testing = false): void
9999
{
100100
$platform = self::detectPlatform($testing);
101101

102-
if (!array_key_exists($platform, self::SUPPORTED_PLATFORMS)) {
102+
if (! array_key_exists($platform, self::SUPPORTED_PLATFORMS)) {
103103
throw new \RuntimeException("Platform $platform is not supported");
104104
}
105105

@@ -113,8 +113,8 @@ public static function installBinary($testing = false): void
113113
$targetFile .= '.exe';
114114
}
115115

116-
if (!is_dir($binDir)) {
117-
if (!mkdir($binDir, 0755, true)) {
116+
if (! is_dir($binDir)) {
117+
if (! mkdir($binDir, 0755, true)) {
118118
throw new \RuntimeException("Failed to create directory: $binDir");
119119
}
120120
}
@@ -135,6 +135,7 @@ public static function installBinary($testing = false): void
135135
$fp = fopen($tempFile, 'w');
136136
if ($fp === false) {
137137
curl_close($ch);
138+
138139
throw new \RuntimeException("Failed to open temporary file for writing");
139140
}
140141

@@ -145,7 +146,7 @@ public static function installBinary($testing = false): void
145146
CURLOPT_FAILONERROR => true,
146147
CURLOPT_TIMEOUT => 300,
147148
CURLOPT_CONNECTTIMEOUT => 30,
148-
CURLOPT_HTTPHEADER => ['User-Agent: volt-test-php-sdk']
149+
CURLOPT_HTTPHEADER => ['User-Agent: volt-test-php-sdk'],
149150
]);
150151

151152
if (curl_exec($ch) === false) {
@@ -160,15 +161,15 @@ public static function installBinary($testing = false): void
160161
curl_close($ch);
161162
fclose($fp);
162163

163-
if (!file_exists($tempFile) || filesize($tempFile) === 0) {
164+
if (! file_exists($tempFile) || filesize($tempFile) === 0) {
164165
throw new \RuntimeException("Downloaded file is empty or missing");
165166
}
166167

167-
if (!rename($tempFile, $targetFile)) {
168+
if (! rename($tempFile, $targetFile)) {
168169
throw new \RuntimeException("Failed to move downloaded binary to: $targetFile");
169170
}
170171

171-
if (!chmod($targetFile, 0755)) {
172+
if (! chmod($targetFile, 0755)) {
172173
throw new \RuntimeException("Failed to set executable permissions on binary");
173174
}
174175

@@ -179,6 +180,7 @@ public static function installBinary($testing = false): void
179180
if (file_exists($tempFile)) {
180181
unlink($tempFile);
181182
}
183+
182184
throw $e;
183185
}
184186
}

src/ProcessManager.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class ProcessManager
1313
public function __construct(string $binaryPath)
1414
{
1515
$this->binaryPath = $binaryPath;
16-
// Enable async signals
1716
if (function_exists('pcntl_async_signals')) {
1817
pcntl_async_signals(true);
1918
pcntl_signal(SIGINT, [$this, 'handleSignal']);
@@ -44,7 +43,14 @@ public function execute(array $config, bool $streamOutput): string
4443
fclose($pipes[0]);
4544

4645
$output = $this->handleProcess($pipes, $streamOutput);
47-
} finally {
46+
47+
// Store stderr content before closing
48+
$stderrContent = '';
49+
if (isset($pipes[2]) && is_resource($pipes[2])) {
50+
rewind($pipes[2]);
51+
$stderrContent = stream_get_contents($pipes[2]);
52+
}
53+
4854
// Clean up pipes
4955
foreach ($pipes as $pipe) {
5056
if (is_resource($pipe)) {
@@ -56,12 +62,24 @@ public function execute(array $config, bool $streamOutput): string
5662
$exitCode = $this->closeProcess($process);
5763
$this->currentProcess = null;
5864
if ($exitCode !== 0) {
59-
throw new RuntimeException('Process failed with exit code ' . $exitCode);
65+
echo "\nError: " . trim($stderrContent) . "\n";
66+
67+
return '';
6068
}
6169
}
62-
}
6370

64-
return $output;
71+
return $output;
72+
} finally {
73+
foreach ($pipes as $pipe) {
74+
if (is_resource($pipe)) {
75+
fclose($pipe);
76+
}
77+
}
78+
if (is_resource($process)) {
79+
$this->closeProcess($process);
80+
$this->currentProcess = null;
81+
}
82+
}
6583
}
6684

6785
protected function openProcess(): array
@@ -149,6 +167,7 @@ protected function closeProcess($process): int
149167
proc_terminate($process);
150168
}
151169

170+
152171
return proc_close($process);
153172
}
154173
}

src/Request.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public function toArray(): array
109109
if (count($this->headers) > 0) {
110110
$array['header'] = $this->headers;
111111
}
112+
112113
return $array;
113114
}
114115

tests/Units/ProcessManagerTest.php

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -63,38 +63,6 @@ public static function outputProvider(): array
6363
];
6464
}
6565

66-
#[DataProvider('errorScenarioProvider')]
67-
public function testErrorScenarios(
68-
bool $failStart,
69-
int $exitCode,
70-
string $errorOutput,
71-
string $expectedMessage
72-
): void {
73-
$this->processManager->setFailProcessStart($failStart);
74-
$this->processManager->setMockExitCode($exitCode);
75-
$this->processManager->setMockStderr($errorOutput);
76-
77-
$this->expectException(\RuntimeException::class);
78-
$this->expectExceptionMessage($expectedMessage);
79-
80-
$this->processManager->execute(['test' => true], false);
81-
}
82-
83-
public static function errorScenarioProvider(): array
84-
{
85-
return [
86-
'process start failure' => [
87-
true, 0, '', 'Failed to start process',
88-
],
89-
'non-zero exit code' => [
90-
false, 1, 'Error occurred', 'Process failed with exit code 1',
91-
],
92-
'permission error' => [
93-
false, 126, 'Permission denied', 'Process failed with exit code 126',
94-
],
95-
];
96-
}
97-
9866
public function testLongRunningProcess(): void
9967
{
10068
$longOutput = str_repeat("Output line\n", 100);

0 commit comments

Comments
 (0)