From f4be49d5e166bc4ae639c5f6ff8f7a67856779ff Mon Sep 17 00:00:00 2001
From: Jean-Paul Calderone <exarkun@twistedmatrix.com>
Date: Wed, 9 Oct 2019 15:50:13 -0400
Subject: [PATCH] Make an implicit assumption about data size explicit in some
 tests

Immutable shares are limited to what you can pay for with 10 passes right
now.  This certainly needs to be lifted but until it is we don't want spurious
test failures telling us about the limit.

Mutable shares are limited to what you can pay for with 1 pass right now
because the client doesn't know how to compute the right number of passes and
always spends 1 pass.
---
 .../tests/test_storage_protocol.py            | 25 +++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/src/_zkapauthorizer/tests/test_storage_protocol.py b/src/_zkapauthorizer/tests/test_storage_protocol.py
index 98320fd..b0b105d 100644
--- a/src/_zkapauthorizer/tests/test_storage_protocol.py
+++ b/src/_zkapauthorizer/tests/test_storage_protocol.py
@@ -140,6 +140,22 @@ class LocalRemote(object):
         )
 
 
+def assume_one_pass(test_and_write_vectors_for_shares):
+    """
+    Assume that the writes represented by the given ``TestAndWriteVectors``
+    will cost at most one pass.
+    """
+    from .._storage_server import (
+        BYTES_PER_PASS,
+        get_sharenums,
+        get_allocated_size,
+        required_passes,
+    )
+    tw_vectors = {k: v.for_call() for (k, v) in test_and_write_vectors_for_shares.items()}
+    sharenums = get_sharenums(tw_vectors)
+    allocated_size = get_allocated_size(tw_vectors)
+    assume(required_passes(BYTES_PER_PASS, sharenums, allocated_size) <= 1)
+
 
 class ShareTests(TestCase):
     """
@@ -194,6 +210,9 @@ class ShareTests(TestCase):
         resulting buckets can be read back using *get_buckets* and methods of
         those resulting buckets.
         """
+        # XXX
+        assume(len(sharenums) * size < 128 * 1024 * 10)
+
         # Hypothesis causes our storage server to be used many times.  Clean
         # up between iterations.
         cleanup_storage_server(self.anonymous_storage_server)
@@ -381,6 +400,9 @@ class ShareTests(TestCase):
         Mutable share data written using *slot_testv_and_readv_and_writev* can be
         read back.
         """
+        # XXX
+        assume_one_pass(test_and_write_vectors_for_shares)
+
         # Hypothesis causes our storage server to be used many times.  Clean
         # up between iterations.
         cleanup_storage_server(self.anonymous_storage_server)
@@ -458,6 +480,9 @@ class ShareTests(TestCase):
         When mutable share data is written using *slot_testv_and_readv_and_writev*
         any leases on the corresponding slot remain the same.
         """
+        # XXX
+        assume_one_pass(test_and_write_vectors_for_shares)
+
         # Hypothesis causes our storage server to be used many times.  Clean
         # up between iterations.
         cleanup_storage_server(self.anonymous_storage_server)
-- 
GitLab