Merge ~ilasc/turnip:trigger-auto-gc into turnip:master

Proposed by Ioana Lasc
Status: Rejected
Rejected by: Ioana Lasc
Proposed branch: ~ilasc/turnip:trigger-auto-gc
Merge into: turnip:master
Diff against target: 75 lines (+60/-0)
1 file modified
turnip/api/tests/test_store.py (+60/-0)
Reviewer Review Type Date Requested Status
Launchpad code reviewers Pending
Review via email: mp+394458@code.launchpad.net

Commit message

Add test to trigger the Git GC

Description of the change

This unit test confirms the inner workings of the Git GC with regard to the threshold where it considers the repository insufficiently packed.

This investigation is work in preparation for the feature document: https://docs.google.com/document/d/1Y4fnuciBsbRQhPjZcbKTVQqHcT7kkrIhHwdByNAIJCo/edit?usp=sharing

The next step here is to trigger the Git GC and have it error out the same way it does in Prod today with: "error: The last gc run reported the following. Please correct the root
cause and remove gc.log."

I'm not proposing this as an actual "I intend to merge this once approved", it's a "keeping progress visible" MP for now.

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) wrote :

Rejecting this as merging this Unit test into Master was never the purpose of the MP.

Practical elements from it have already been used in https://code.launchpad.net/~ilasc/turnip/+git/turnip/+merge/394581 and "theory verification" elements will be documented in the feature document: https://docs.google.com/document/d/1Y4fnuciBsbRQhPjZcbKTVQqHcT7kkrIhHwdByNAIJCo/edit?usp=sharing

Unmerged commits

1972951... by Ioana Lasc

Add test to trigger the Git GC

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/turnip/api/tests/test_store.py b/turnip/api/tests/test_store.py
index 5108581..23f7de1 100644
--- a/turnip/api/tests/test_store.py
+++ b/turnip/api/tests/test_store.py
@@ -10,6 +10,7 @@ from __future__ import (
10import os.path10import os.path
11import re11import re
12import subprocess12import subprocess
13import time
13import uuid14import uuid
1415
15from fixtures import (16from fixtures import (
@@ -446,3 +447,62 @@ class InitTestCase(TestCase):
446 self.assertEqual(before_refs_len - 1, len(orig.references.objects))447 self.assertEqual(before_refs_len - 1, len(orig.references.objects))
447 self.assertNotIn(448 self.assertNotIn(
448 new_branch_name, [i.name for i in orig.references.objects])449 new_branch_name, [i.name for i in orig.references.objects])
450
451 def test_pre_gc_auto_hook(self):
452
453 curdir = os.getcwd()
454 gc_path = os.path.join(self.repo_store, 'test_gc/')
455 gc_factory = RepoFactory(
456 gc_path, num_branches=3, num_commits=300, num_tags=3)
457 os.mkdir(os.path.join(gc_path, 'worktree'))
458 gc_factory.build()
459 os.chdir(os.path.join(gc_path, 'worktree'))
460 repo_config = pygit2.Repository(gc_path).config
461
462 # set gc.auto to a low value to verify git's threshlod
463 # for triggering auto packing of the repository
464 repo_config['gc.auto'] = 1
465 repo_config['core.bare'] = False
466 repo_config['core.worktree'] = os.path.join(gc_path, 'worktree')
467 assert 'gc.auto' in repo_config
468 assert repo_config.get_int('gc.auto') == 1
469 assert 'core.worktree' in repo_config
470 assert repo_config['core.worktree']
471
472 files = os.listdir(os.path.join(gc_path, 'objects/17'))
473 self.assertGreater(len(files), repo_config.get_int('gc.auto'))
474 repo = pygit2.Repository(gc_path)
475 branch = repo.lookup_branch('master')
476 ref = repo.lookup_reference(branch.name)
477 repo.checkout(ref)
478 oid = gc_factory.add_commit('foo', 'foobar.txt')
479 repo.head.set_target(oid)
480 repo.index.write()
481
482 # a repository with 300 commits and 3 branches should have
483 # around 2700 loose objects under objects/17
484 # we assert that their number is above 0 at this point
485 objects = subprocess.check_output(['git', 'count-objects'])
486 self.assertGreater(int(objects[0:(objects.find(' objects'))]), 0)
487
488 # at this point we have more objects in forlder objects/17 than
489 # we define in the config file under gc.auto and
490 # with the next commit automated garbace collection will trigger
491 commit_output = subprocess.check_output(
492 ['git commit -m \"test_commit_message\"'],
493 stderr=subprocess.STDOUT, shell=True)
494
495 m1 = "Auto packing the repository in background"
496 m2 = "for optimum performance."
497 self.assertIn(m1+" "+m2, commit_output)
498
499 # give gc 2 seconds to run
500 time.sleep(2)
501
502 # after above commit automated gc ran and there will
503 # be 0 loose objects as they just got repacked by gc
504 free_objects = subprocess.check_output(['git', 'count-objects'])
505 self.assertEquals(
506 int(free_objects[0:(free_objects.find(' objects'))]),
507 0)
508 os.chdir(curdir)

Subscribers

People subscribed via source and target branches