sapling/tests/test-hgsql-repolock.t
Thomas Orozco 398d8bcc1f hgsql: expose reason on top of sqlisreporeadonly
Summary:
This introduces `repo.sqlreporeadonlystate()`, which works similarly to `repo.sqlisreporeadonly()`, but also gets the reason why the read only state is the way it is.

The underlying goal is to use this in a repo hook to report the lock state.

I retained the `sqlisreporeadonly` function so that we don't need to synchronize deployment of this code and the underlying hook.

Reviewed By: quark-zju

Differential Revision: D15165946

fbshipit-source-id: 0a62147167fa826b575178dd261990a956b5f317
2019-05-02 09:08:51 -07:00

79 lines
3.6 KiB
Raku

$ . "$TESTDIR/hgsql/library.sh"
$ initserver master masterrepo
$ cd master
Check that a repo without an entry is treated as RW
$ hg debugshell -c "print(repo.sqlreporeadonlystate())"
(False, 'no reason was provided')
$ hg debugshell -c "print(repo.sqlisreporeadonly())"
False
Set the repo to RO for hg and mononoke
$ mysql -h $DBHOST -P $DBPORT -D $DBNAME -u $DBUSER $DBPASSOPT -e 'REPLACE INTO repo_lock(repo, state) VALUES ("masterrepo", 0)'
$ hg debugshell -c "print(repo.sqlreporeadonlystate())"
(True, 'no reason was provided')
$ hg debugshell -c "print(repo.sqlisreporeadonly())"
True
Set another repo to RW for hg and check that masterrepo is still RO
$ mysql -h $DBHOST -P $DBPORT -D $DBNAME -u $DBUSER $DBPASSOPT -e 'REPLACE INTO repo_lock(repo, state) VALUES ("masterrepo2", 1)'
$ hg debugshell -c "print(repo.sqlreporeadonlystate())"
(True, 'no reason was provided')
$ hg debugshell -c "print(repo.sqlisreporeadonly())"
True
Set the repo to RW for Mononoke only
$ mysql -h $DBHOST -P $DBPORT -D $DBNAME -u $DBUSER $DBPASSOPT -e 'REPLACE INTO repo_lock(repo, state) VALUES ("masterrepo", 2)'
$ hg debugshell -c "print(repo.sqlreporeadonlystate())"
(True, 'writes are being served by Mononoke (fburl.com/mononoke)')
$ hg debugshell -c "print(repo.sqlisreporeadonly())"
True
Set the repo to RW for hg only
$ mysql -h $DBHOST -P $DBPORT -D $DBNAME -u $DBUSER $DBPASSOPT -e 'REPLACE INTO repo_lock(repo, state) VALUES ("masterrepo", 1)'
$ hg debugshell -c "print(repo.sqlreporeadonlystate())"
(False, 'no reason was provided')
$ hg debugshell -c "print(repo.sqlisreporeadonly())"
False
Set the repo to RO again
$ mysql -h $DBHOST -P $DBPORT -D $DBNAME -u $DBUSER $DBPASSOPT -e 'REPLACE INTO repo_lock(repo, state) VALUES ("masterrepo", 0)'
$ hg debugshell -c "print(repo.sqlreporeadonlystate())"
(True, 'no reason was provided')
$ hg debugshell -c "print(repo.sqlisreporeadonly())"
True
Set the repo to RO for hg and mononoke (with reason)
$ mysql -h $DBHOST -P $DBPORT -D $DBNAME -u $DBUSER $DBPASSOPT -e 'REPLACE INTO repo_lock(repo, state, reason) VALUES ("masterrepo", 0, "reason123")'
$ hg debugshell -c "print(repo.sqlreporeadonlystate())"
(True, 'reason123')
$ hg debugshell -c "print(repo.sqlisreporeadonly())"
True
Set another repo to RW (with reason) for hg and check that masterrepo is still RO
$ mysql -h $DBHOST -P $DBPORT -D $DBNAME -u $DBUSER $DBPASSOPT -e 'REPLACE INTO repo_lock(repo, state, reason) VALUES ("masterrepo2", 1, "reason456")'
$ hg debugshell -c "print(repo.sqlreporeadonlystate())"
(True, 'reason123')
$ hg debugshell -c "print(repo.sqlisreporeadonly())"
True
Set the repo to RW for Mononoke only (with reason)
$ mysql -h $DBHOST -P $DBPORT -D $DBNAME -u $DBUSER $DBPASSOPT -e 'REPLACE INTO repo_lock(repo, state, reason) VALUES ("masterrepo", 2, "reason123")'
$ hg debugshell -c "print(repo.sqlreporeadonlystate())"
(True, 'reason123')
$ hg debugshell -c "print(repo.sqlisreporeadonly())"
True
Set the repo to RW for hg only (with reason)
$ mysql -h $DBHOST -P $DBPORT -D $DBNAME -u $DBUSER $DBPASSOPT -e 'REPLACE INTO repo_lock(repo, state, reason) VALUES ("masterrepo", 1, "reason123")'
$ hg debugshell -c "print(repo.sqlreporeadonlystate())"
(False, 'reason123')
$ hg debugshell -c "print(repo.sqlisreporeadonly())"
False
Set the repo to RO again (with reason)
$ mysql -h $DBHOST -P $DBPORT -D $DBNAME -u $DBUSER $DBPASSOPT -e 'REPLACE INTO repo_lock(repo, state, reason) VALUES ("masterrepo", 0, "reason123")'
$ hg debugshell -c "print(repo.sqlreporeadonlystate())"
(True, 'reason123')
$ hg debugshell -c "print(repo.sqlisreporeadonly())"
True