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
1diff --git a/turnip/api/tests/test_store.py b/turnip/api/tests/test_store.py
2index 5108581..23f7de1 100644
3--- a/turnip/api/tests/test_store.py
4+++ b/turnip/api/tests/test_store.py
5@@ -10,6 +10,7 @@ from __future__ import (
6 import os.path
7 import re
8 import subprocess
9+import time
10 import uuid
11
12 from fixtures import (
13@@ -446,3 +447,62 @@ class InitTestCase(TestCase):
14 self.assertEqual(before_refs_len - 1, len(orig.references.objects))
15 self.assertNotIn(
16 new_branch_name, [i.name for i in orig.references.objects])
17+
18+ def test_pre_gc_auto_hook(self):
19+
20+ curdir = os.getcwd()
21+ gc_path = os.path.join(self.repo_store, 'test_gc/')
22+ gc_factory = RepoFactory(
23+ gc_path, num_branches=3, num_commits=300, num_tags=3)
24+ os.mkdir(os.path.join(gc_path, 'worktree'))
25+ gc_factory.build()
26+ os.chdir(os.path.join(gc_path, 'worktree'))
27+ repo_config = pygit2.Repository(gc_path).config
28+
29+ # set gc.auto to a low value to verify git's threshlod
30+ # for triggering auto packing of the repository
31+ repo_config['gc.auto'] = 1
32+ repo_config['core.bare'] = False
33+ repo_config['core.worktree'] = os.path.join(gc_path, 'worktree')
34+ assert 'gc.auto' in repo_config
35+ assert repo_config.get_int('gc.auto') == 1
36+ assert 'core.worktree' in repo_config
37+ assert repo_config['core.worktree']
38+
39+ files = os.listdir(os.path.join(gc_path, 'objects/17'))
40+ self.assertGreater(len(files), repo_config.get_int('gc.auto'))
41+ repo = pygit2.Repository(gc_path)
42+ branch = repo.lookup_branch('master')
43+ ref = repo.lookup_reference(branch.name)
44+ repo.checkout(ref)
45+ oid = gc_factory.add_commit('foo', 'foobar.txt')
46+ repo.head.set_target(oid)
47+ repo.index.write()
48+
49+ # a repository with 300 commits and 3 branches should have
50+ # around 2700 loose objects under objects/17
51+ # we assert that their number is above 0 at this point
52+ objects = subprocess.check_output(['git', 'count-objects'])
53+ self.assertGreater(int(objects[0:(objects.find(' objects'))]), 0)
54+
55+ # at this point we have more objects in forlder objects/17 than
56+ # we define in the config file under gc.auto and
57+ # with the next commit automated garbace collection will trigger
58+ commit_output = subprocess.check_output(
59+ ['git commit -m \"test_commit_message\"'],
60+ stderr=subprocess.STDOUT, shell=True)
61+
62+ m1 = "Auto packing the repository in background"
63+ m2 = "for optimum performance."
64+ self.assertIn(m1+" "+m2, commit_output)
65+
66+ # give gc 2 seconds to run
67+ time.sleep(2)
68+
69+ # after above commit automated gc ran and there will
70+ # be 0 loose objects as they just got repacked by gc
71+ free_objects = subprocess.check_output(['git', 'count-objects'])
72+ self.assertEquals(
73+ int(free_objects[0:(free_objects.find(' objects'))]),
74+ 0)
75+ os.chdir(curdir)

Subscribers

People subscribed via source and target branches