|
3 | 3 | namespace Pterodactyl\Tests\Integration\Services\Servers; |
4 | 4 |
|
5 | 5 | use Mockery; |
| 6 | +use GuzzleHttp\Psr7\Request; |
| 7 | +use GuzzleHttp\Psr7\Response; |
6 | 8 | use Pterodactyl\Models\Server; |
7 | 9 | use Pterodactyl\Models\Allocation; |
| 10 | +use GuzzleHttp\Exception\RequestException; |
| 11 | +use GuzzleHttp\Exception\TransferException; |
8 | 12 | use Pterodactyl\Exceptions\DisplayException; |
9 | 13 | use Pterodactyl\Tests\Integration\IntegrationTestCase; |
10 | 14 | use Pterodactyl\Repositories\Wings\DaemonServerRepository; |
11 | 15 | use Pterodactyl\Services\Servers\BuildModificationService; |
| 16 | +use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException; |
12 | 17 |
|
13 | 18 | class BuildModificationServiceTest extends IntegrationTestCase |
14 | 19 | { |
@@ -149,6 +154,30 @@ public function testServerBuildDataIsProperlyUpdatedOnWings() |
149 | 154 | $this->assertSame(20, $response->allocation_limit); |
150 | 155 | } |
151 | 156 |
|
| 157 | + /** |
| 158 | + * Test that an exception when connecting to the Wings instance is properly ignored |
| 159 | + * when making updates. This allows for a server to be modified even when the Wings |
| 160 | + * node is offline. |
| 161 | + */ |
| 162 | + public function testConnectionExceptionIsIgnoredWhenUpdatingServerSettings() |
| 163 | + { |
| 164 | + $server = $this->createServerModel(); |
| 165 | + |
| 166 | + $this->daemonServerRepository->expects('setServer->update')->andThrows( |
| 167 | + new DaemonConnectionException( |
| 168 | + new RequestException('Bad request', new Request('GET', '/test'), new Response()) |
| 169 | + ) |
| 170 | + ); |
| 171 | + |
| 172 | + $response = $this->getService()->handle($server, ['memory' => 256, 'disk' => 10240]); |
| 173 | + |
| 174 | + $this->assertInstanceOf(Server::class, $response); |
| 175 | + $this->assertSame(256, $response->memory); |
| 176 | + $this->assertSame(10240, $response->disk); |
| 177 | + |
| 178 | + $this->assertDatabaseHas('servers', ['id' => $response->id, 'memory' => 256, 'disk' => 10240]); |
| 179 | + } |
| 180 | + |
152 | 181 | /** |
153 | 182 | * Test that no exception is thrown if we are only removing an allocation. |
154 | 183 | */ |
@@ -215,7 +244,9 @@ public function testUsingSameAllocationIdMultipleTimesDoesNotError() |
215 | 244 |
|
216 | 245 | /** |
217 | 246 | * Test that any changes we made to the server or allocations are rolled back if there is an |
218 | | - * exception while performing any action. |
| 247 | + * exception while performing any action. This is different than the connection exception |
| 248 | + * test which should properly ignore connection issues. We want any other type of exception |
| 249 | + * to properly be thrown back to the caller. |
219 | 250 | */ |
220 | 251 | public function testThatUpdatesAreRolledBackIfExceptionIsEncountered() |
221 | 252 | { |
|
0 commit comments