-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Fix SSH multiplexing contention for concurrent scheduled tasks (#6736) #7503
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| <?php | ||
|
|
||
| namespace Tests\Unit; | ||
|
|
||
| use App\Helpers\SshMultiplexingHelper; | ||
| use Tests\TestCase; | ||
|
|
||
| /** | ||
| * Tests for SSH multiplexing disable functionality. | ||
| * | ||
| * These tests verify the parameter signatures for the disableMultiplexing feature | ||
| * which prevents race conditions when multiple scheduled tasks run concurrently. | ||
| * | ||
| * @see https://github.com/coollabsio/coolify/issues/6736 | ||
| */ | ||
| class SshMultiplexingDisableTest extends TestCase | ||
| { | ||
| public function test_generate_ssh_command_method_exists() | ||
| { | ||
| $this->assertTrue( | ||
| method_exists(SshMultiplexingHelper::class, 'generateSshCommand'), | ||
| 'generateSshCommand method should exist' | ||
| ); | ||
| } | ||
|
|
||
| public function test_generate_ssh_command_accepts_disable_multiplexing_parameter() | ||
| { | ||
| $reflection = new \ReflectionMethod(SshMultiplexingHelper::class, 'generateSshCommand'); | ||
| $parameters = $reflection->getParameters(); | ||
|
|
||
| // Should have at least 3 parameters: $server, $command, $disableMultiplexing | ||
| $this->assertGreaterThanOrEqual(3, count($parameters)); | ||
|
|
||
| $disableMultiplexingParam = $parameters[2] ?? null; | ||
| $this->assertNotNull($disableMultiplexingParam); | ||
| $this->assertEquals('disableMultiplexing', $disableMultiplexingParam->getName()); | ||
| $this->assertTrue($disableMultiplexingParam->isDefaultValueAvailable()); | ||
| $this->assertFalse($disableMultiplexingParam->getDefaultValue()); | ||
| } | ||
|
|
||
| public function test_disable_multiplexing_parameter_is_boolean_type() | ||
| { | ||
| $reflection = new \ReflectionMethod(SshMultiplexingHelper::class, 'generateSshCommand'); | ||
| $parameters = $reflection->getParameters(); | ||
|
|
||
| $disableMultiplexingParam = $parameters[2] ?? null; | ||
| $this->assertNotNull($disableMultiplexingParam); | ||
|
|
||
| $type = $disableMultiplexingParam->getType(); | ||
| $this->assertNotNull($type); | ||
| $this->assertEquals('bool', $type->getName()); | ||
| } | ||
|
|
||
| public function test_instant_remote_process_accepts_disable_multiplexing_parameter() | ||
| { | ||
| $this->assertTrue( | ||
| function_exists('instant_remote_process'), | ||
| 'instant_remote_process function should exist' | ||
| ); | ||
|
|
||
| $reflection = new \ReflectionFunction('instant_remote_process'); | ||
| $parameters = $reflection->getParameters(); | ||
|
|
||
| // Find the disableMultiplexing parameter | ||
| $disableMultiplexingParam = null; | ||
| foreach ($parameters as $param) { | ||
| if ($param->getName() === 'disableMultiplexing') { | ||
| $disableMultiplexingParam = $param; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| $this->assertNotNull($disableMultiplexingParam, 'disableMultiplexing parameter should exist'); | ||
| $this->assertTrue($disableMultiplexingParam->isDefaultValueAvailable()); | ||
| $this->assertFalse($disableMultiplexingParam->getDefaultValue()); | ||
| } | ||
|
|
||
| public function test_instant_remote_process_disable_multiplexing_is_boolean_type() | ||
| { | ||
| $reflection = new \ReflectionFunction('instant_remote_process'); | ||
| $parameters = $reflection->getParameters(); | ||
|
|
||
| // Find the disableMultiplexing parameter | ||
| $disableMultiplexingParam = null; | ||
| foreach ($parameters as $param) { | ||
| if ($param->getName() === 'disableMultiplexing') { | ||
| $disableMultiplexingParam = $param; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| $this->assertNotNull($disableMultiplexingParam); | ||
|
|
||
| $type = $disableMultiplexingParam->getType(); | ||
| $this->assertNotNull($type); | ||
| $this->assertEquals('bool', $type->getName()); | ||
| } | ||
|
|
||
| public function test_multiplexing_is_skipped_when_disabled() | ||
| { | ||
| // This test verifies the logic flow by checking the code path | ||
| // When disableMultiplexing is true, the condition `! $disableMultiplexing && self::isMultiplexingEnabled()` | ||
| // should evaluate to false, skipping multiplexing entirely | ||
|
|
||
| // We verify the condition logic: | ||
| // disableMultiplexing = true -> ! true = false -> condition is false -> skip multiplexing | ||
| $disableMultiplexing = true; | ||
| $this->assertFalse(! $disableMultiplexing, 'When disableMultiplexing is true, negation should be false'); | ||
|
|
||
| // disableMultiplexing = false -> ! false = true -> condition may proceed | ||
| $disableMultiplexing = false; | ||
| $this->assertTrue(! $disableMultiplexing, 'When disableMultiplexing is false, negation should be true'); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test only verifies basic boolean logic (
!trueand!false) rather than testing the actual implementation behavior. Consider adding integration tests that:SshMultiplexingHelper::generateSshCommand()method withdisableMultiplexing=trueto verify it doesn't add multiplexing SSH options-o ControlMaster=autowhen disabledSshMultiplexingHelper.phpcorrectly skips multiplexing setup when the parameter is trueThis would provide meaningful test coverage of the feature rather than just testing language semantics.