forked from TrueCloudLab/s3-tests
realistic.py: update seek() implementation
seek() requires whence param. Missing it broke readwrite test with boto 2.4.0. Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
This commit is contained in:
parent
f1f86a0de0
commit
d346415f79
1 changed files with 14 additions and 6 deletions
|
@ -6,6 +6,7 @@ import time
|
||||||
import math
|
import math
|
||||||
import tempfile
|
import tempfile
|
||||||
import shutil
|
import shutil
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
NANOSECOND = int(1e9)
|
NANOSECOND = int(1e9)
|
||||||
|
@ -27,10 +28,17 @@ class RandomContentFile(object):
|
||||||
def _mark_chunk(self):
|
def _mark_chunk(self):
|
||||||
self.chunks.append([self.offset, int(round((time.time() - self.last_seek) * NANOSECOND))])
|
self.chunks.append([self.offset, int(round((time.time() - self.last_seek) * NANOSECOND))])
|
||||||
|
|
||||||
def seek(self, offset):
|
def seek(self, offset, whence=os.SEEK_SET):
|
||||||
assert offset == 0
|
if whence == os.SEEK_SET:
|
||||||
|
self.offset = offset
|
||||||
|
elif whence == os.SEEK_END:
|
||||||
|
self.offset = self.size + offset;
|
||||||
|
elif whence == os.SEEK_CUR:
|
||||||
|
self.offset += offset
|
||||||
|
|
||||||
|
assert self.offset == 0
|
||||||
|
|
||||||
self.random.seed(self.seed)
|
self.random.seed(self.seed)
|
||||||
self.offset = offset
|
|
||||||
self.buffer = ''
|
self.buffer = ''
|
||||||
|
|
||||||
self.hash = hashlib.md5()
|
self.hash = hashlib.md5()
|
||||||
|
@ -95,10 +103,10 @@ class PrecomputedContentFile(object):
|
||||||
self.last_chunks = self.chunks = None
|
self.last_chunks = self.chunks = None
|
||||||
self.seek(0)
|
self.seek(0)
|
||||||
|
|
||||||
def seek(self, offset):
|
def seek(self, offset, whence=os.SEEK_SET):
|
||||||
self._file.seek(offset)
|
self._file.seek(offset, whence)
|
||||||
|
|
||||||
if offset == 0:
|
if self.tell() == 0:
|
||||||
# only reset the chunks when seeking to the beginning
|
# only reset the chunks when seeking to the beginning
|
||||||
self.last_chunks = self.chunks
|
self.last_chunks = self.chunks
|
||||||
self.last_seek = time.time()
|
self.last_seek = time.time()
|
||||||
|
|
Loading…
Reference in a new issue