From 814125668bd466e6c8bc9cf5765927072ea35117 Mon Sep 17 00:00:00 2001 From: eeliu <27064129+eeliu@users.noreply.github.com> Date: Fri, 12 Jul 2024 17:56:59 +0800 Subject: [PATCH] remove weight in mm - add testcase --- .github/workflows/main.yml | 5 ++++ .../Plugins/SysV2/_memcached/Mem_Test.php | 26 +++++++++++++++++++ .../Plugins/SysV2/_memcached/memcached.php | 8 +++--- lib/Pinpoint/test/TraceTest.php | 4 ++- 4 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 lib/Pinpoint/Plugins/SysV2/_memcached/Mem_Test.php diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1aac1fe..64263bf 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -31,6 +31,11 @@ jobs: image: redis ports: - 6379:6379 + + memcached: + image: memcached:alpine3.20 + ports: + - "11211:11211" steps: - uses: actions/checkout@v2 - name: Setup PHP diff --git a/lib/Pinpoint/Plugins/SysV2/_memcached/Mem_Test.php b/lib/Pinpoint/Plugins/SysV2/_memcached/Mem_Test.php new file mode 100644 index 0000000..1e0baf2 --- /dev/null +++ b/lib/Pinpoint/Plugins/SysV2/_memcached/Mem_Test.php @@ -0,0 +1,26 @@ +assertTrue(extension_loaded('memcached')); + $mc = new Memcached(); + $mc->addServer("localhost", 11211); + $mc->set('key', "abc"); + $this->assertTrue($mc->get('key') == 'abc'); // boolean false + var_dump($mc->getResultCode()); // int 0 which is Memcached::RES_SUCCESS + var_dump($mc->add("test_add", 234)); // int 0 which is Memcached::RES_SUCCESS + // var_dump($Memcached->appendByKey("xxx", "test_add", 234)); // int 0 which is Memcached::RES_SUCCESS + var_dump($mc->delete("test_add")); // int 0 which is Memcached::RES_SUCCESS + var_dump($mc->deleteMulti(["test_add", "a", "b", "c"])); // int 0 which is Memcached::RES_SUCCESS + } +} \ No newline at end of file diff --git a/lib/Pinpoint/Plugins/SysV2/_memcached/memcached.php b/lib/Pinpoint/Plugins/SysV2/_memcached/memcached.php index 770b638..346d477 100644 --- a/lib/Pinpoint/Plugins/SysV2/_memcached/memcached.php +++ b/lib/Pinpoint/Plugins/SysV2/_memcached/memcached.php @@ -28,15 +28,15 @@ use Memcached; -function format_host(Memcached $Memcached): string +function format_host(Memcached $memcached): string { - $servers = $Memcached->getServerList(); + $servers = $memcached->getServerList(); $ret = ""; foreach ($servers as $ser) { $host = $ser['host']; $port = $ser['port']; - $weight = $ser['weight']; - $ret .= "memcached(host=$host,port=$port,weight=$weight)"; + // removed weight + $ret .= "memcached(host=$host,port=$port)"; } return $ret; } diff --git a/lib/Pinpoint/test/TraceTest.php b/lib/Pinpoint/test/TraceTest.php index 95dad71..aeb71be 100644 --- a/lib/Pinpoint/test/TraceTest.php +++ b/lib/Pinpoint/test/TraceTest.php @@ -34,7 +34,9 @@ public function checkKeys(array $keys): bool { $message = static::$logger_->message_; foreach ($keys as $key => $time) { - $this->assertEquals(substr_count($message, $key), $time); + $real = substr_count($message, $key); + $target = $time; + $this->assertEquals($real, $target, "key=$key,real=$real, target=$target {$message}"); } return True; }