From 4f0f9d7cefe096d7f516e6c289e232a5507050b5 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 20 Oct 2018 11:58:23 +0300 Subject: Add: test-persistence --- test-persistence | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 test-persistence diff --git a/test-persistence b/test-persistence new file mode 100755 index 0000000..1b5b836 --- /dev/null +++ b/test-persistence @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 +# Copyright (C) 2018 Lars Wirzenius +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + + +import os +import sys + + +import muck + + +def changes(n): + res = { + 'foo': 'bar', + } + + for i in range(n): + meta = { + 'id': 'id-{}'.format(i), + 'rev': 'rev-{}'.format(i), + } + chg = muck.CreateChange(meta=meta, res=res) + yield chg + + +def compare_dicts(d1, d2): + for key in d1: + if key not in d2: + return 'Missing key: {}'.format(key) + + for key in d2: + if key not in d1: + return 'Extra key: {}'.format(key) + + for key in d1: + v1 = d1[key] + v2 = d2[key] + if v1 != v2: + return 'Different values: {}: {} vs {}'.format(key, v1, v2) + + return None + + +store_dir = sys.argv[1] +n = int(sys.argv[2]) + +os.mkdir(store_dir) +st = muck.Store(store_dir) +for i, chg in enumerate(changes(n)): + st.change(chg) + + st2 = muck.Store(store_dir) + ms = st.get_memory_store() + ms2 = st2.get_memory_store() + err = compare_dicts(ms.as_dict(), ms2.as_dict()) + if err: + sys.stderr.write('ERROR: {}: {}\n'.format(i+1, err)) + sys.exit(1) + +sys.stdout.write('OK\n') -- cgit v1.2.1