Skip to content

Commit

Permalink
Migrate setTimeout from Float to Int
Browse files Browse the repository at this point in the history
  • Loading branch information
igor committed Jun 9, 2022
1 parent c8fa3e3 commit 99484e8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ $config = [
];
$db = new ClickHouseDB\Client($config);
$db->database('default');
$db->setTimeout(1.5); // 1500 ms
$db->setTimeout(1.5); // 1 second , support only Int value
$db->setTimeout(10); // 10 seconds
$db->setConnectTimeOut(5); // 5 seconds
$db->ping(true); // if can`t connect throw exception
Expand Down Expand Up @@ -788,7 +788,7 @@ $cli->ping();
$result=$cl->truncateTable('dbNane.TableName_sharded');

// get one active node ( random )
$cl->activeClient()->setTimeout(0.01);
$cl->activeClient()->setTimeout(500);
$cl->activeClient()->write("DROP TABLE IF EXISTS default.asdasdasd ON CLUSTER cluster2");


Expand Down
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public function setHost($host)
/**
* @return Settings
*/
public function setTimeout(float $timeout)
public function setTimeout(int $timeout)
{
return $this->settings()->max_execution_time($timeout);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ public function makeSessionId()
}

/**
* @param int|float $time
* @param int $time
* @return $this
*/
public function max_execution_time($time)
{
$this->set('max_execution_time', $time);
$this->set('max_execution_time', intval($time));
return $this;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -918,13 +918,13 @@ public function testInsertTableTimeout()
$this->create_table_summing_url_views();


$this->client->setTimeout(0.01);
$this->client->settings()->set('max_execution_time',0.1);


$stat = $this->client->insertBatchFiles('summing_url_views', $file_data_names, [
'event_time', 'url_hash', 'site_id', 'views', 'v_00', 'v_55'
]);
$this->client->ping();

}
/**
*
Expand Down
15 changes: 11 additions & 4 deletions tests/FormatQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,23 @@ public function testClientTimeoutSettings()
{
$this->client->database('default');

$timeout = 1.5;
$timeout = 0.55;
$this->client->setTimeout($timeout); // 1500 ms
$this->assertSame($timeout, $this->client->getTimeout());
$this->client->select('SELECT 123,123 as ping ')->rows();
$this->assertSame(intval($timeout), $this->client->getTimeout());

$timeout = 10.0;
$this->client->setTimeout($timeout); // 10 seconds
$this->assertSame($timeout, $this->client->getTimeout());
$this->client->select('SELECT 123,123 as ping ')->rows();
$this->assertSame(intval($timeout), $this->client->getTimeout());

$timeout = 5.0;
$timeout = 5.14;
$this->client->setConnectTimeOut($timeout); // 5 seconds
$this->client->select('SELECT 123,123 as ping ')->rows();
$this->assertSame(5, $this->client->getConnectTimeOut());
}




}

0 comments on commit 99484e8

Please sign in to comment.