Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 401 and 402] [Versions 401 and 403]

DML read/read-write database handle use tests

Copyright: 2018 Srdjan Janković, Catalyst IT
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 573 lines (20 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 3 files
 lib/dml/tests/fixtures/read_slave_moodle_database_special.php
 lib/dml/tests/fixtures/read_slave_moodle_database_table_names.php
 lib/tests/fixtures/event_fixtures.php

Defines 1 class


Class: dml_read_slave_test  - X-Ref

DML read/read-write database handle use tests

new_db($wantlatency = false,$readonly = [['dbhost' => 'test_ro1', 'dbport' => 1, 'dbuser' => 'test1', 'dbpass' => 'test1'],['dbhost' => 'test_ro2', 'dbport' => 2, 'dbuser' => 'test2', 'dbpass' => 'test2'],['dbhost' => 'test_ro3', 'dbport' => 3, 'dbuser' => 'test3', 'dbpass' => 'test3'],],$dbclass = read_slave_moodle_database::class)   X-Ref
Instantiates a test database interface object.

param: bool $wantlatency
param: mixed $readonly
param: mixed $dbclass
return: read_slave_moodle_database $db

assert_readonly_handle($handle)   X-Ref
Asert that the mock handle returned from read_slave_moodle_database methods
is a readonly slave handle.

param: string $handle
return: void

table_names_provider()   X-Ref
moodle_read_slave_trait::table_names() test data provider

return: array

test_table_names($sql, $tables)   X-Ref
Test moodle_read_slave_trait::table_names() query parser.

param: string $sql
param: array $tables
return: void

test_read_read_write_read()   X-Ref
Test correct database handles are used in a read-read-write-read scenario.
Test lazy creation of the write handle.

return: void

test_read_write_write()   X-Ref
Test correct database handles are used in a read-write-write scenario.

return: void

test_write_read_read()   X-Ref
Test correct database handles are used in a write-read-read scenario.

return: void

test_read_temptable()   X-Ref
Test readonly handle is not used for reading from temptables.

return: void

test_read_excluded_tables()   X-Ref
Test readonly handle is not used for reading from excluded tables.

return: void

test_transaction()   X-Ref
Test readonly handle is not used during transactions.
Test last written time is adjusted post-transaction,
so the latency parameter is applied properly.

return: void

test_long_update()   X-Ref
Test readonly handle is not used immediately after update
Test last written time is adjusted post-write,
so the latency parameter is applied properly.

return: void

test_transaction_with_events()   X-Ref
Test readonly handle is not used with events
when the latency parameter is applied properly.

return: void

test_read_only_conn_fail()   X-Ref
Test failed readonly connection falls back to write connection.

return: void

test_read_only_conn_first_fail()   X-Ref
In multiple slaves scenario, test failed readonly connection falls back to
another readonly connection.

return: void

with_global_db($test)   X-Ref
Helper to restore global $DB

param: callable $test
return: void

test_lock_db()   X-Ref
Test lock_db table exclusion

return: void

test_sessions()   X-Ref
Test sessions table exclusion

return: void