tests/test-sqlitestore.t
author Manuel Jacob <me@manueljacob.de>
Mon, 11 Jul 2022 01:51:20 +0200
branchstable
changeset 49378 094a5fa3cf52
parent 48669 7ee07e1a25c0
permissions -rw-r--r--
procutil: make stream detection in make_line_buffered more correct and strict In make_line_buffered(), we don’t want to wrap the stream if we know that lines get flushed to the underlying raw stream already. Previously, the heuristic was too optimistic. It assumed that any stream which is not an instance of io.BufferedIOBase doesn’t need wrapping. However, there are buffered streams that aren’t instances of io.BufferedIOBase, like Mercurial’s own winstdout. The new logic is different in two ways: First, only for the check, if unwraps any combination of WriteAllWrapper and winstdout. Second, it skips wrapping the stream only if it is an instance of io.RawIOBase (or already wrapped). If it is an instance of io.BufferedIOBase, it gets wrapped. In any other case, the function raises an exception. This ensures that, if an unknown stream is passed or we add another wrapper in the future, we don’t wrap the stream if it’s already line buffered or not wrap the stream if it’s not line buffered. In fact, this was already helpful during development of this change. Without it, I possibly would have forgot that WriteAllWrapper needs to be ignored for the check, leading to unnecessary wrapping if stdout is unbuffered. The alternative would have been to always wrap unknown streams. However, I don’t think that anyone would benefit from being less strict. We can expect streams from the standard library to be subclassing either io.RawIOBase or io.BufferedIOBase, so running Mercurial in the standard way should not regress by this change. Py2exe might replace sys.stdout and sys.stderr, but that currently breaks Mercurial anyway and also these streams don’t claim to be interactive, so this function is not called for them.

#require sqlite no-chg

The sqlitestore backend leaves transactions around when used with chg.
Since this backend is primarily intended as proof-of-concept for
alternative storage backends, disable it for chg test runs to avoid
the instability.

  $ cat >> $HGRCPATH <<EOF
  > [extensions]
  > sqlitestore =
  > EOF

New repo should not use SQLite by default

  $ hg init empty-no-sqlite
  $ hg debugrequires -R empty-no-sqlite
  dotencode
  dirstate-v2 (dirstate-v2 !)
  fncache
  generaldelta
  persistent-nodemap (rust !)
  revlog-compression-zstd (zstd !)
  revlogv1
  share-safe
  sparserevlog
  store

storage.new-repo-backend=sqlite is recognized

  $ hg --config storage.new-repo-backend=sqlite init empty-sqlite
  $ hg debugrequires -R empty-sqlite
  dotencode
  dirstate-v2 (dirstate-v2 !)
  exp-sqlite-001
  exp-sqlite-comp-001=zstd (zstd !)
  exp-sqlite-comp-001=$BUNDLE2_COMPRESSIONS$ (no-zstd !)
  fncache
  generaldelta
  persistent-nodemap (rust !)
  revlog-compression-zstd (zstd !)
  revlogv1
  share-safe
  sparserevlog
  store

  $ cat >> $HGRCPATH << EOF
  > [storage]
  > new-repo-backend = sqlite
  > EOF

Can force compression to zlib

  $ hg --config storage.sqlite.compression=zlib init empty-zlib
  $ hg debugrequires -R empty-zlib
  dotencode
  dirstate-v2 (dirstate-v2 !)
  exp-sqlite-001
  exp-sqlite-comp-001=$BUNDLE2_COMPRESSIONS$
  fncache
  generaldelta
  persistent-nodemap (rust !)
  revlog-compression-zstd (zstd !)
  revlogv1
  share-safe
  sparserevlog
  store

Can force compression to none

  $ hg --config storage.sqlite.compression=none init empty-none
  $ hg debugrequires -R empty-none
  dotencode
  dirstate-v2 (dirstate-v2 !)
  exp-sqlite-001
  exp-sqlite-comp-001=none
  fncache
  generaldelta
  persistent-nodemap (rust !)
  revlog-compression-zstd (zstd !)
  revlogv1
  share-safe
  sparserevlog
  store

Can make a local commit

  $ hg init local-commit
  $ cd local-commit
  $ echo 0 > foo
  $ hg commit -A -m initial
  adding foo

That results in a row being inserted into various tables

  $ sqlite3 .hg/store/db.sqlite -init /dev/null << EOF
  > SELECT * FROM filepath;
  > EOF
  1|foo

  $ sqlite3 .hg/store/db.sqlite -init /dev/null << EOF
  > SELECT * FROM fileindex;
  > EOF
  1|1|0|-1|-1|0|0|1||6/\xef(L\xe2\xca\x02\xae\xcc\x8d\xe6\xd5\xe8\xa1\xc3\xaf\x05V\xfe (esc)

  $ sqlite3 .hg/store/db.sqlite -init /dev/null << EOF
  > SELECT * FROM delta;
  > EOF
  1|1|	\xd2\xaf\x8d\xd2"\x01\xdd\x8dH\xe5\xdc\xfc\xae\xd2\x81\xff\x94"\xc7|0 (esc)
  

Tracking multiple files works

  $ echo 1 > bar
  $ hg commit -A -m 'add bar'
  adding bar

  $ sqlite3 .hg/store/db.sqlite -init /dev/null << EOF
  > SELECT * FROM filedata ORDER BY id ASC;
  > EOF
  1|1|foo|0|6/\xef(L\xe2\xca\x02\xae\xcc\x8d\xe6\xd5\xe8\xa1\xc3\xaf\x05V\xfe|-1|-1|0|0|1| (esc)
  2|2|bar|0|\xb8\xe0/d3s\x80!\xa0e\xf9Au\xc7\xcd#\xdb_\x05\xbe|-1|-1|1|0|2| (esc)

Multiple revisions of a file works

  $ echo a >> foo
  $ hg commit -m 'modify foo'

  $ sqlite3 .hg/store/db.sqlite -init /dev/null << EOF
  > SELECT * FROM filedata ORDER BY id ASC;
  > EOF
  1|1|foo|0|6/\xef(L\xe2\xca\x02\xae\xcc\x8d\xe6\xd5\xe8\xa1\xc3\xaf\x05V\xfe|-1|-1|0|0|1| (esc)
  2|2|bar|0|\xb8\xe0/d3s\x80!\xa0e\xf9Au\xc7\xcd#\xdb_\x05\xbe|-1|-1|1|0|2| (esc)
  3|1|foo|1|\xdd\xb3V\xcd\xde1p@\xf7\x8e\x90\xb8*\x8b,\xe9\x0e\xd6j+|0|-1|2|0|3|1 (esc)

  $ cd ..