Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 108... Línea 108...
108
            $this->redis->del($keyname);
108
            $this->redis->del($keyname);
109
        }
109
        }
110
        $this->redis->close();
110
        $this->redis->close();
111
    }
111
    }
Línea 112... Línea 112...
112
 
112
 
113
    public function test_normal_session_read_only() {
113
    public function test_normal_session_read_only(): void {
114
        $sess = new \core\session\redis();
114
        $sess = new \core\session\redis();
115
        $sess->set_requires_write_lock(false);
115
        $sess->set_requires_write_lock(false);
116
        $sess->init();
116
        $sess->init();
117
        $this->assertSame('', $sess->read('sess1'));
117
        $this->assertSame('', $sess->read('sess1'));
118
        $this->assertTrue($sess->close());
118
        $this->assertTrue($sess->close());
Línea 119... Línea 119...
119
    }
119
    }
120
 
120
 
121
    public function test_normal_session_start_stop_works() {
121
    public function test_normal_session_start_stop_works(): void {
122
        $sess = new \core\session\redis();
122
        $sess = new \core\session\redis();
123
        $sess->init();
123
        $sess->init();
124
        $sess->set_requires_write_lock(true);
124
        $sess->set_requires_write_lock(true);
Línea 133... Línea 133...
133
        $this->assertTrue($sess->write('sess1', 'DATA-new'));
133
        $this->assertTrue($sess->write('sess1', 'DATA-new'));
134
        $this->assertTrue($sess->close());
134
        $this->assertTrue($sess->close());
135
        $this->assertSessionNoLocks();
135
        $this->assertSessionNoLocks();
136
    }
136
    }
Línea 137... Línea 137...
137
 
137
 
138
    public function test_compression_read_and_write_works() {
138
    public function test_compression_read_and_write_works(): void {
Línea 139... Línea 139...
139
        global $CFG;
139
        global $CFG;
Línea 140... Línea 140...
140
 
140
 
Línea 157... Línea 157...
157
        }
157
        }
Línea 158... Línea 158...
158
 
158
 
159
        $CFG->session_redis_compressor = \core\session\redis::COMPRESSION_NONE;
159
        $CFG->session_redis_compressor = \core\session\redis::COMPRESSION_NONE;
Línea 160... Línea 160...
160
    }
160
    }
161
 
161
 
162
    public function test_session_blocks_with_existing_session() {
162
    public function test_session_blocks_with_existing_session(): void {
163
        $sess = new \core\session\redis();
163
        $sess = new \core\session\redis();
164
        $sess->init();
164
        $sess->init();
165
        $sess->set_requires_write_lock(true);
165
        $sess->set_requires_write_lock(true);
Línea 194... Línea 194...
194
        $this->assertTrue($sess->write('sess1', 'DATA-new'));
194
        $this->assertTrue($sess->write('sess1', 'DATA-new'));
195
        $this->assertTrue($sess->close());
195
        $this->assertTrue($sess->close());
196
        $this->assertSessionNoLocks();
196
        $this->assertSessionNoLocks();
197
    }
197
    }
Línea 198... Línea 198...
198
 
198
 
199
    public function test_session_is_destroyed_when_it_does_not_exist() {
199
    public function test_session_is_destroyed_when_it_does_not_exist(): void {
200
        $sess = new \core\session\redis();
200
        $sess = new \core\session\redis();
201
        $sess->init();
201
        $sess->init();
202
        $sess->set_requires_write_lock(true);
202
        $sess->set_requires_write_lock(true);
203
        $this->assertTrue($sess->open('Not used', 'Not used'));
203
        $this->assertTrue($sess->open('Not used', 'Not used'));
204
        $this->assertTrue($sess->destroy('sess-destroy'));
204
        $this->assertTrue($sess->destroy('sess-destroy'));
205
        $this->assertSessionNoLocks();
205
        $this->assertSessionNoLocks();
Línea 206... Línea 206...
206
    }
206
    }
207
 
207
 
208
    public function test_session_is_destroyed_when_we_have_it_open() {
208
    public function test_session_is_destroyed_when_we_have_it_open(): void {
209
        $sess = new \core\session\redis();
209
        $sess = new \core\session\redis();
210
        $sess->init();
210
        $sess->init();
211
        $sess->set_requires_write_lock(true);
211
        $sess->set_requires_write_lock(true);
212
        $this->assertTrue($sess->open('Not used', 'Not used'));
212
        $this->assertTrue($sess->open('Not used', 'Not used'));
213
        $this->assertSame('', $sess->read('sess-destroy'));
213
        $this->assertSame('', $sess->read('sess-destroy'));
214
        $this->assertTrue($sess->destroy('sess-destroy'));
214
        $this->assertTrue($sess->destroy('sess-destroy'));
215
        $this->assertTrue($sess->close());
215
        $this->assertTrue($sess->close());
Línea 216... Línea 216...
216
        $this->assertSessionNoLocks();
216
        $this->assertSessionNoLocks();
217
    }
217
    }
218
 
218
 
219
    public function test_multiple_sessions_do_not_interfere_with_each_other() {
219
    public function test_multiple_sessions_do_not_interfere_with_each_other(): void {
220
        $sess1 = new \core\session\redis();
220
        $sess1 = new \core\session\redis();
221
        $sess1->set_requires_write_lock(true);
221
        $sess1->set_requires_write_lock(true);
Línea 258... Línea 258...
258
 
258
 
259
        // Read the session again to ensure locking did what it should.
259
        // Read the session again to ensure locking did what it should.
260
        $this->assertSessionNoLocks();
260
        $this->assertSessionNoLocks();
Línea 261... Línea 261...
261
    }
261
    }
262
 
262
 
263
    public function test_multiple_sessions_work_with_a_single_instance() {
263
    public function test_multiple_sessions_work_with_a_single_instance(): void {
264
        $sess = new \core\session\redis();
264
        $sess = new \core\session\redis();
Línea 265... Línea 265...
265
        $sess->init();
265
        $sess->init();
Línea 279... Línea 279...
279
        $this->assertSessionNoLocks();
279
        $this->assertSessionNoLocks();
Línea 280... Línea 280...
280
 
280
 
281
        $this->assertTrue($sess->close());
281
        $this->assertTrue($sess->close());
Línea 282... Línea 282...
282
    }
282
    }
283
 
283
 
284
    public function test_session_exists_returns_valid_values() {
284
    public function test_session_exists_returns_valid_values(): void {
285
        $sess = new \core\session\redis();
285
        $sess = new \core\session\redis();
Línea 286... Línea 286...
286
        $sess->init();
286
        $sess->init();
Línea 294... Línea 294...
294
        $this->assertTrue($sess->session_exists('sess1'), 'Session must exist now.');
294
        $this->assertTrue($sess->session_exists('sess1'), 'Session must exist now.');
295
        $this->assertTrue($sess->destroy('sess1'));
295
        $this->assertTrue($sess->destroy('sess1'));
296
        $this->assertFalse($sess->session_exists('sess1'), 'Session should be destroyed.');
296
        $this->assertFalse($sess->session_exists('sess1'), 'Session should be destroyed.');
297
    }
297
    }
Línea 298... Línea 298...
298
 
298
 
299
    public function test_kill_sessions_removes_the_session_from_redis() {
299
    public function test_kill_sessions_removes_the_session_from_redis(): void {
Línea 300... Línea 300...
300
        global $DB;
300
        global $DB;
301
 
301
 
Línea 330... Línea 330...
330
        $this->assertEquals(3, $DB->count_records('sessions'), 'Moodle handles session database, plugin must not change it.');
330
        $this->assertEquals(3, $DB->count_records('sessions'), 'Moodle handles session database, plugin must not change it.');
331
        $this->assertSessionNoLocks();
331
        $this->assertSessionNoLocks();
332
        $this->assertEmpty($this->redis->keys($this->keyprefix.'*'), 'There should be no session data left.');
332
        $this->assertEmpty($this->redis->keys($this->keyprefix.'*'), 'There should be no session data left.');
333
    }
333
    }
Línea 334... Línea 334...
334
 
334
 
335
    public function test_exception_when_connection_attempts_exceeded() {
335
    public function test_exception_when_connection_attempts_exceeded(): void {
Línea 336... Línea 336...
336
        global $CFG;
336
        global $CFG;
337
 
337
 
Línea 359... Línea 359...
359
     */
359
     */
360
    protected function assertSessionNoLocks() {
360
    protected function assertSessionNoLocks() {
361
        $this->assertEmpty($this->redis->keys($this->keyprefix.'*.lock'));
361
        $this->assertEmpty($this->redis->keys($this->keyprefix.'*.lock'));
362
    }
362
    }
Línea 363... Línea 363...
363
 
363
 
364
    public function test_session_redis_encrypt() {
364
    public function test_session_redis_encrypt(): void {
Línea 365... Línea 365...
365
        global $CFG;
365
        global $CFG;
Línea 366... Línea 366...
366
 
366