Skip to content

Commit

Permalink
remove weight in mm
Browse files Browse the repository at this point in the history
- add testcase
  • Loading branch information
eeliu committed Jul 12, 2024
1 parent b578af2 commit 63ded95
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,19 @@ jobs:
image: redis
ports:
- 6379:6379

memcached:
image: memcached:alpine3.20
ports:
- "11211:11211"
steps:
- uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: composer:v2
extensions: pinpoint_php-https://github.com/pinpoint-apm/pinpoint-c-agent@dev, mongodb-mongodb/[email protected]
extensions: pinpoint_php-https://github.com/pinpoint-apm/pinpoint-c-agent@dev, mongodb-mongodb/[email protected], php-memcached-dev/[email protected]
- run: |
composer install --prefer-dist
vendor/bin/phpunit --configuration PHPUnit_aop_libraries.xml --testsuit pinpoint --testdox
25 changes: 25 additions & 0 deletions lib/Pinpoint/Plugins/SysV2/_memcached/Mem_Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Pinpoint\Plugins\SysV2\_memcached;

use Pinpoint\test\TraceTest;

use Memcached;

// vendor/bin/phpunit --configuration PHPUnit_aop_libraries.xml --testsuit pinpoint --testdox --filter Mem_Test
class Mem_Test extends TraceTest
{

public function test_mem_flow()
{
$mc = new Memcached();
$mc->addServer("memcached", 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
}
}
8 changes: 4 additions & 4 deletions lib/Pinpoint/Plugins/SysV2/_memcached/memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/Pinpoint/test/TraceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 63ded95

Please sign in to comment.