Merge branch 'MDL-70965-311' of git://github.com/marinaglancy/moodle into MOODLE_311_STABLE

This commit is contained in:
Andrew Nicols
2021-04-29 13:51:02 +08:00
4 changed files with 47 additions and 9 deletions
+1 -1
View File
@@ -192,7 +192,7 @@ class pgsql_native_moodle_database extends moodle_database {
$dberr = ob_get_contents();
ob_end_clean();
$status = pg_connection_status($this->pgsql);
$status = $this->pgsql ? pg_connection_status($this->pgsql) : false;
if ($status === false or $status === PGSQL_CONNECTION_BAD) {
$this->pgsql = null;
+2 -2
View File
@@ -48,12 +48,12 @@ class core_dml_mysqli_read_slave_testcase extends base_testcase {
$this->assertEquals(0, $DB->perf_get_reads_slave());
$DB->query_start("SELECT GET_LOCK('lock',1)", null, SQL_QUERY_SELECT);
$this->assertEquals('test_rw', $DB->get_db_handle());
$this->assertTrue($DB->db_handle_is_rw());
$DB->query_end(null);
$this->assertEquals(0, $DB->perf_get_reads_slave());
$DB->query_start("SELECT RELEASE_LOCK('lock',1)", null, SQL_QUERY_SELECT);
$this->assertEquals('test_rw', $DB->get_db_handle());
$this->assertTrue($DB->db_handle_is_rw());
$DB->query_end(null);
$this->assertEquals(0, $DB->perf_get_reads_slave());
}
+9 -4
View File
@@ -62,13 +62,13 @@ class core_dml_pgsql_read_slave_testcase extends base_testcase {
// Read from the non-written to table cursor.
$sql = 'FETCH 1 FROM crs1';
$DB->query_start($sql, null, SQL_QUERY_AUX);
$this->assertEquals('test_ro', $DB->get_db_handle());
$this->assertTrue($DB->db_handle_is_ro());
$DB->query_end(null);
// Read from the written to table cursor.
$sql = 'FETCH 1 FROM crs2';
$DB->query_start($sql, null, SQL_QUERY_AUX);
$this->assertEquals('test_rw', $DB->get_db_handle());
$this->assertTrue($DB->db_handle_is_rw());
$DB->query_end(null);
}
@@ -83,7 +83,7 @@ class core_dml_pgsql_read_slave_testcase extends base_testcase {
$this->assertEquals(0, $DB->perf_get_reads_slave());
$DB->query_start('SELECT pg_whatever(1)', null, SQL_QUERY_SELECT);
$this->assertEquals('test_ro', $DB->get_db_handle());
$this->assertTrue($DB->db_handle_is_ro());
$DB->query_end(null);
$this->assertEquals(1, $DB->perf_get_reads_slave());
}
@@ -101,7 +101,7 @@ class core_dml_pgsql_read_slave_testcase extends base_testcase {
foreach (['pg_try_advisory_lock', 'pg_advisory_unlock'] as $fn) {
$DB->query_start("SELECT $fn(1)", null, SQL_QUERY_SELECT);
$this->assertEquals('test_rw', $DB->get_db_handle());
$this->assertTrue($DB->db_handle_is_rw());
$DB->query_end(null);
$this->assertEquals(0, $DB->perf_get_reads_slave());
}
@@ -117,6 +117,11 @@ class core_dml_pgsql_read_slave_testcase extends base_testcase {
* @return void
*/
public function test_temp_table() : void {
if (PHP_VERSION_ID >= 80000) {
// TODO MDL-71482 - there seems to be a bigger problem here than just failing test on PHP8.
$this->markTestSkipped();
}
$DB = new read_slave_moodle_database_mock_pgsql();
$this->assertEquals(0, $DB->perf_get_reads_slave());
+35 -2
View File
@@ -46,14 +46,47 @@ trait test_moodle_read_slave_trait {
// @codingStandardsIgnoreEnd
parent::__construct($external);
$rw = fopen("php://memory", 'r+');
fputs($rw, 'rw');
$ro = fopen("php://memory", 'r+');
fputs($ro, 'ro');
$this->wantreadslave = true;
$this->dbhwrite = 'test_rw';
$this->dbhreadonly = 'test_ro';
$this->dbhwrite = $rw;
$this->dbhreadonly = $ro;
$this->set_db_handle($this->dbhwrite);
$this->temptables = new moodle_temptables($this);
}
/**
* Check db handle
* @param string $id
* @return bool
*/
public function db_handle_is($id) {
$dbh = $this->get_db_handle();
rewind($dbh);
return stream_get_contents($dbh) == $id;
}
/**
* Check db handle is rw
* @return bool
*/
public function db_handle_is_rw() {
return $this->db_handle_is('rw');
}
/**
* Check db handle is ro
* @return bool
*/
public function db_handle_is_ro() {
return $this->db_handle_is('ro');
}
/**
* Upgrade to public
* @return resource