commit.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 Commit(Check):
  13. def initialize(self) -> Testdrive:
  14. return Testdrive(
  15. dedent(
  16. """
  17. > CREATE TABLE commit_table (f1 INTEGER);
  18. """
  19. )
  20. )
  21. def manipulate(self) -> list[Testdrive]:
  22. return [
  23. Testdrive(dedent(s))
  24. for s in [
  25. """
  26. > BEGIN
  27. > INSERT INTO commit_table VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
  28. # We want the transaction to take more than 1 second
  29. $ sleep-is-probably-flaky-i-have-justified-my-need-with-a-comment duration="1s"
  30. > INSERT INTO commit_table VALUES (11), (12), (13), (14), (15), (16), (17), (18), (19), (20);
  31. > COMMIT
  32. """,
  33. """
  34. > BEGIN
  35. > INSERT INTO commit_table VALUES (21), (22), (23), (24), (25), (26), (27), (28), (29), (30);
  36. # We want the transaction to take more than 1 second
  37. $ sleep-is-probably-flaky-i-have-justified-my-need-with-a-comment duration="1s"
  38. > INSERT INTO commit_table VALUES (31), (32), (33), (34), (35), (36), (37), (38), (39), (40);
  39. > COMMIT
  40. """,
  41. ]
  42. ]
  43. def validate(self) -> Testdrive:
  44. return Testdrive(
  45. dedent(
  46. """
  47. > SELECT COUNT(*), COUNT(f1), COUNT(DISTINCT f1), MIN(f1), MAX(f1) FROM commit_table;
  48. 40 40 40 1 40
  49. """
  50. )
  51. )