Skip to content

Commit bd4fce4

Browse files
authored
update CI to run tests on each commit.
update CI to run tests on each commit.
1 parent 598fece commit bd4fce4

File tree

4 files changed

+136
-1
lines changed

4 files changed

+136
-1
lines changed

.github/workflows/php.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ on:
3333
- .github/workflows/install-engine/action.yml
3434
- .github/workflows/create-test-matrices/action.yml
3535
- .github/json_matrices/**
36+
# PHP-specific paths
37+
- "*.c"
38+
- "*.h"
39+
- "*.php"
40+
- "*.stub.php"
41+
- tests/**
42+
- examples/**
43+
- composer.json
44+
- composer.lock
45+
- config.m4
46+
- Makefile.frag
47+
- phpcs.xml
48+
- phpstan.neon
49+
- include/**
50+
- src/**
3651
workflow_dispatch:
3752
inputs:
3853
full-matrix:

tests/ValkeyGlideClusterFeaturesTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,4 +559,65 @@ public function testConstructorWithCommonConfiguration()
559559
$this->assertTrue($valkey_glide->ping(['type' => 'primarySlotKey', 'key' => 'test']));
560560
$valkey_glide->close();
561561
}
562+
563+
public function testClusterClientCreateDeleteLoop()
564+
{
565+
// Simple test that creates and deletes ValkeyGlideCluster clients in a loop
566+
$loopCount = 500; // Fewer iterations for cluster due to overhead
567+
$successCount = 0;
568+
$errorCount = 0;
569+
$startMemory = memory_get_usage(true);
570+
571+
echo "Testing cluster client create/delete loop with {$loopCount} iterations...\n";
572+
573+
for ($i = 1; $i <= $loopCount; $i++) {
574+
try {
575+
// Create a new cluster client using the base class method
576+
$client = $this->newInstance();
577+
578+
// Verify the client works with a cluster-specific ping
579+
$route = ['type' => 'primarySlotKey', 'key' => 'test'];
580+
$this->assertTrue($client->ping($route), "Cluster client ping failed on iteration {$i}");
581+
582+
// Close the client
583+
$client->close();
584+
585+
// Explicitly unset to help with cleanup
586+
unset($client);
587+
588+
$successCount++;
589+
590+
// Log progress every 5 iterations (fewer than standalone due to lower count)
591+
if ($i % 100 == 0) {
592+
echo "Completed {$i}/{$loopCount} iterations...\n";
593+
}
594+
595+
} catch (Exception $e) {
596+
$errorCount++;
597+
echo "Error on iteration {$i}: " . $e->getMessage() . "\n";
598+
599+
// Continue with the test even if some iterations fail
600+
continue;
601+
}
602+
}
603+
604+
$endMemory = memory_get_usage(true);
605+
$memoryGrowth = $endMemory - $startMemory;
606+
607+
// Log final results
608+
echo "Cluster Create/Delete Loop Test Results:\n";
609+
echo "- Total iterations: {$loopCount}\n";
610+
echo "- Successful iterations: {$successCount}\n";
611+
echo "- Failed iterations: {$errorCount}\n";
612+
echo "- Memory growth: " . round($memoryGrowth / 1024, 2) . " KB\n";
613+
614+
// Assert that most iterations were successful
615+
$successRate = $successCount / $loopCount;
616+
$this->assertTrue($successRate > 0.9, "Success rate should be > 90%, got " . round($successRate * 100, 1) . "%");
617+
618+
// Warn if memory growth is significant
619+
if ($memoryGrowth > 5 * 1024 * 1024) { // More than 5MB
620+
echo "WARNING: Significant memory growth detected: " . round($memoryGrowth / 1024 / 1024, 2) . " MB\n";
621+
}
622+
}
562623
}

tests/ValkeyGlideFeaturesTest.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,4 +838,64 @@ public function testLoggerWithValkeyGlideIntegration()
838838
$this->cleanupLogFile($log_file_with_date);
839839
}
840840
}
841+
842+
public function testClientCreateDeleteLoop()
843+
{
844+
// Simple test that creates and deletes ValkeyGlide clients in a loop
845+
$loopCount = 100;
846+
$successCount = 0;
847+
$errorCount = 0;
848+
$startMemory = memory_get_usage(true);
849+
850+
echo "Testing client create/delete loop with {$loopCount} iterations...\n";
851+
852+
for ($i = 1; $i <= $loopCount; $i++) {
853+
try {
854+
// Create a new client using the base class method
855+
$client = $this->newInstance();
856+
857+
// Verify the client works
858+
$this->assertTrue($client->ping(), "Client ping failed on iteration {$i}");
859+
860+
// Close the client
861+
$client->close();
862+
863+
// Explicitly unset to help with cleanup
864+
unset($client);
865+
866+
$successCount++;
867+
868+
// Log progress every 10 iterations
869+
if ($i % 10 == 0) {
870+
echo "Completed {$i}/{$loopCount} iterations...\n";
871+
}
872+
873+
} catch (Exception $e) {
874+
$errorCount++;
875+
echo "Error on iteration {$i}: " . $e->getMessage() . "\n";
876+
877+
// Continue with the test even if some iterations fail
878+
continue;
879+
}
880+
}
881+
882+
$endMemory = memory_get_usage(true);
883+
$memoryGrowth = $endMemory - $startMemory;
884+
885+
// Log final results
886+
echo "Create/Delete Loop Test Results:\n";
887+
echo "- Total iterations: {$loopCount}\n";
888+
echo "- Successful iterations: {$successCount}\n";
889+
echo "- Failed iterations: {$errorCount}\n";
890+
echo "- Memory growth: " . round($memoryGrowth / 1024, 2) . " KB\n";
891+
892+
// Assert that most iterations were successful
893+
$successRate = $successCount / $loopCount;
894+
$this->assertTrue($successRate > 0.9, "Success rate should be > 90%, got " . round($successRate * 100, 1) . "%");
895+
896+
// Warn if memory growth is significant
897+
if ($memoryGrowth > 5 * 1024 * 1024) { // More than 5MB
898+
echo "WARNING: Significant memory growth detected: " . round($memoryGrowth / 1024 / 1024, 2) . " MB\n";
899+
}
900+
}
841901
}

valkey_glide_core_commands.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,6 @@ void close_glide_client(const void* glide_client) {
727727
if (!glide_client) {
728728
return;
729729
}
730-
731730
/* Close the client using the close_client function from glide_bindings.h */
732731
close_client(glide_client);
733732
}

0 commit comments

Comments
 (0)