Change in vdsm[master]: tests: Replace magic number with constant

nsoffer at redhat.com nsoffer at redhat.com
Sat Mar 19 16:25:54 UTC 2016


Nir Soffer has uploaded a new change for review.

Change subject: tests: Replace magic number with constant
......................................................................

tests: Replace magic number with constant

Add BLOCK_SIZE constant and use it to replace sizes and offsets for
direct I/O tests.

Change-Id: Ibf89be2b776650ba189db9cca7bd1e2cfdd7b2a9
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M tests/storage_directio_test.py
1 file changed, 9 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/54/54954/1

diff --git a/tests/storage_directio_test.py b/tests/storage_directio_test.py
index 9098c15..559d1ba 100644
--- a/tests/storage_directio_test.py
+++ b/tests/storage_directio_test.py
@@ -26,6 +26,8 @@
 
 from vdsm.storage import directio
 
+BLOCK_SIZE = 512
+
 
 @expandPermutations
 class TestDirectFile(TestCaseBase):
@@ -33,13 +35,13 @@
     DATA = b"".join(c * 127 + b"\n"
                     for c in (b"a", b"b", b"c", b"d", b"e", b"f", b"g", b"h"))
 
-    @permutations([[0], [512], [1024], [1024 + 512]])
+    @permutations([[i * BLOCK_SIZE] for i in range(4)])
     def test_read(self, size):
         with temporaryPath(data=self.DATA) as srcPath, \
                 directio.DirectFile(srcPath, "r") as f:
             self.assertEquals(f.read(size), self.DATA[:size])
 
-    @permutations([[512], [1024]])
+    @permutations([[1 * BLOCK_SIZE], [2 * BLOCK_SIZE]])
     def test_seek_and_read(self, offset):
         with temporaryPath(data=self.DATA) as srcPath, \
                 directio.DirectFile(srcPath, "r") as f:
@@ -56,8 +58,8 @@
     def test_small_writes(self):
         with temporaryPath() as srcPath, \
                 directio.DirectFile(srcPath, "w") as f:
-            f.write(self.DATA[:512])
-            f.write(self.DATA[512:])
+            f.write(self.DATA[:BLOCK_SIZE])
+            f.write(self.DATA[BLOCK_SIZE:])
 
             with io.open(srcPath, "rb") as f:
                 self.assertEquals(f.read(), self.DATA)
@@ -72,11 +74,11 @@
     def test_update_and_read(self):
         with temporaryPath() as srcPath, \
                 directio.DirectFile(srcPath, "w") as f:
-            f.write(self.DATA[:512])
+            f.write(self.DATA[:BLOCK_SIZE])
 
             with directio.DirectFile(srcPath, "r+") as f:
-                f.seek(512)
-                f.write(self.DATA[512:])
+                f.seek(BLOCK_SIZE)
+                f.write(self.DATA[BLOCK_SIZE:])
 
             with io.open(srcPath, "rb") as f:
                 self.assertEquals(f.read(), self.DATA)


-- 
To view, visit https://gerrit.ovirt.org/54954
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibf89be2b776650ba189db9cca7bd1e2cfdd7b2a9
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer at redhat.com>


More information about the vdsm-patches mailing list