~free.ekanayaka/storm/any-expr

« back to all changes in this revision

Viewing changes to tests/store/base.py

Merge mutable-variables-flush-leak [r=jkakar,jukart]

Remove a leak when mutable variables (ListVariable or PickleVariable instances) are
collected before store.flush, leaving hooks behind them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
421
421
        self.store.flush()
422
422
        self.assertEquals(len(events), 1)
423
423
 
 
424
    def test_wb_flush_event_with_deleted_object_before_flush(self):
 
425
        """
 
426
        When an object is deleted before flush and it contains mutable
 
427
        variables, those variables unhook from the global event system to
 
428
        prevent a leak.
 
429
        """
 
430
        class PickleBlob(Blob):
 
431
            bin = Pickle()
 
432
 
 
433
        # Disable the cache, which holds strong references.
 
434
        self.get_cache(self.store).set_size(0)
 
435
 
 
436
        blob = self.store.get(Blob, 20)
 
437
        blob.bin = "\x80\x02}q\x01U\x01aK\x01s."
 
438
        self.store.flush()
 
439
        del blob
 
440
        gc.collect()
 
441
 
 
442
        pickle_blob = self.store.get(PickleBlob, 20)
 
443
        pickle_blob.bin = "foobin"
 
444
        del pickle_blob
 
445
 
 
446
        self.store.flush()
 
447
        self.assertEquals(self.store._event._hooks["flush"], set())
 
448
 
 
449
 
424
450
    def test_obj_info_with_deleted_object_with_get(self):
425
451
        # Same thing, but using get rather than find.
426
452