rollback.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. from textwrap import dedent
  10. from materialize.checks.actions import Testdrive
  11. from materialize.checks.checks import Check
  12. class Rollback(Check):
  13. def initialize(self) -> Testdrive:
  14. return Testdrive(
  15. dedent(
  16. """
  17. > CREATE TABLE rollback_table (f1 INTEGER);
  18. > INSERT INTO rollback_table VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
  19. """
  20. )
  21. )
  22. def manipulate(self) -> list[Testdrive]:
  23. return [
  24. Testdrive(dedent(s))
  25. for s in [
  26. """
  27. > BEGIN
  28. > INSERT INTO rollback_table VALUES (11), (12), (13), (14), (15), (16), (17), (18), (19), (20);
  29. # We want the transaction to take more than 1 second
  30. $ sleep-is-probably-flaky-i-have-justified-my-need-with-a-comment duration="1s"
  31. > INSERT INTO rollback_table VALUES (21), (22), (23), (24), (25), (26), (27), (28), (29), (30);
  32. > ROLLBACK;
  33. """,
  34. """
  35. > BEGIN
  36. > INSERT INTO rollback_table VALUES (31), (32), (33), (34), (35), (36), (37), (38), (39), (40);
  37. # We want the transaction to take more than 1 second
  38. $ sleep-is-probably-flaky-i-have-justified-my-need-with-a-comment duration="1s"
  39. > INSERT INTO rollback_table VALUES (41), (42), (43), (44), (45), (46), (47), (48), (49), (50);
  40. > ROLLBACK;
  41. """,
  42. ]
  43. ]
  44. def validate(self) -> Testdrive:
  45. return Testdrive(
  46. dedent(
  47. """
  48. > SELECT COUNT(*), COUNT(f1), COUNT(DISTINCT f1), MIN(f1), MAX(f1) FROM rollback_table;
  49. 10 10 10 1 10
  50. """
  51. )
  52. )