Project

General

Profile

Bug #56996 ยป cephbug.py

Witold Baryluk, 08/01/2022 04:32 PM

 
#!/usr/bin/env python3

import os
import random
import sys
import time

FILENAME = sys.argv[1]

total_file_size = 0

while True:
with open(FILENAME, "a+b") as f:
a = []
total_size = 0
target_size = random.randint(10 * 1024, 2 * 1024 * 1024)
while total_size < target_size:
if random.random() > 0.5:
x = 'a' + 'b' * random.randint(100, 200) + "c\n"
a.append(x)
total_size += len(x)
else:
y = 'F' + 'G' * random.randint(100, 200) + "H\n"
a.append(y)
total_size += len(y)
data = "".join(a)
chunk_size = 32 * 1024
i = 0
while i < len(data):
chunk = data[i : i + chunk_size]
i += len(chunk)
f.write(chunk.encode())
total_file_size += len(data)
time.sleep(0.1e-3 * random.random()) # 0us - 100us

time.sleep(0.1)

# Sporadically remove the file
if total_file_size > 300 * 1024 * 1024:
os.unlink(FILENAME)
total_file_size = 0
    (1-1/1)