# LogicTest: local local-opt local-parallel-stmts fakedist fakedist-opt fakedist-metadata

subtest automatic_retry

# On an implicit transaction, we retry automatically and the function
# eventually returns a result.
query I
SELECT crdb_internal.force_retry('50ms':::INTERVAL)
----
0

subtest automatic_retry

statement ok
BEGIN TRANSACTION; SAVEPOINT cockroach_restart

# The SELECT 1 is necessary to take the session out of the AutoRetry state,
# otherwise the statement below would be retries automatically.
statement ok
SELECT 1

query error restart transaction: HandledRetryableTxnError: forced by crdb_internal.force_retry()
SELECT crdb_internal.force_retry('500ms':::INTERVAL)

statement ok
ROLLBACK TO SAVEPOINT cockroach_restart

# wait until the transaction is at least 1 second
sleep 1s

statement ok
SAVEPOINT cockroach_restart

query I
SELECT crdb_internal.force_retry('500ms':::INTERVAL)
----
0

statement ok
COMMIT

subtest schema_chage_with_rollback

# Test that creating a table repeatedly across restarts doesn't leave dangling
# rows behind (the rows are  associated with the correct descriptor).
# See #24785.

statement ok
BEGIN

statement ok
SAVEPOINT cockroach_restart

statement ok
CREATE TABLE t (
id INT PRIMARY KEY
)

statement ok
ROLLBACK TO SAVEPOINT cockroach_restart

# The following CREATE shouldn't be necessary. This test would like to just run
# the next insert (or a select) and check that it fails to resolve the table
# name. However, that doesn't currently work because of #24885.
statement ok
CREATE TABLE t (
id INT PRIMARY KEY
)

statement ok
INSERT INTO t (id) VALUES (1);

statement ok
COMMIT

query I
SELECT id FROM t
----
1
