Skip to content

Commit 74fa2e5

Browse files
committedApr 28, 2023
Add ability to generate files of specific size
We need to be able to generate files of specific sizes to carry out quantity tests and perhaps it would have other uses. Issue: PermanentOrg#13 Signed-off-by: fenn-cs <[email protected]>
1 parent 812ff7b commit 74fa2e5

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed
 

‎README.md

+36
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,42 @@ Run
174174
Check the downloads folder in `test-tree/downloads` and ensure that the `downloads/nested` directory has a structure like the nested directory uploaded in the [nested uploads test](#nested-uploads).
175175

176176

177+
#### Quantity Tests
178+
179+
To test uploads/downloads with a large number of files, we definitely need "a large number" of files on either side (local/remote) of the process.
180+
181+
To generate a number of files with a specific size in `test-tree/special-files`, run `./create-files.py --quantity 10 --size 10000 --root-name "10-10B"` (*In this case, the command would generate 10, 10 bytes files.*)
182+
183+
*Take note that in the command `--quantity`, `--size` and `--root-name` are arguments whose values you can change. Quanity for number of files, size for file zie and root name for the name of the parent folder that would hold the files*
184+
##### Large number of uploads
185+
186+
For 1000, 1B Files:
187+
- Run `./create-files.py`
188+
189+
- Run `./upload-test.py test-tree/special-files/1000-1B --remote-dir=1000-10B --log-file=log-1000-1B.txt --remote=prod --archive-path="/archives/QA (0a21-0000)/My Files/"`
190+
191+
For 1000, 10B Files:
192+
- Run `./create-files.py --quantity 1000 --size 10000 --root-name "1000-10B"`
193+
194+
- Run `./upload-test.py test-tree/special-files/1000-10B --remote-dir=1000-10B --log-file=log-1000-10B.txt --remote=prod --archive-path="/archives/QA (0a21-0000)/My Files/"`
195+
196+
For 1000, 1MB Files:
197+
- Run `./create-files.py --quantity 1000 --size 1000000 --root-name "1000-1MB"`
198+
199+
- Run `./upload-test.py test-tree/special-files/1000-1MB --remote-dir=1000-1MB --log-file=log-1000-1MB.txt --remote=prod --archive-path="/archives/QA (0a21-0000)/My Files/"`
200+
201+
For 1000, 5MB Files:
202+
- Run `./create-files.py --quantity 1000 --size 5000000 --root-name "1000-5MB"`
203+
204+
- Run `./upload-test.py test-tree/special-files/1000-5MB --remote-dir=1000-5MB --log-file=log-1000-5MB.txt --remote=prod --archive-path="/archives/QA (0a21-0000)/My Files/"`
205+
206+
*Of course, by looking at the pattern above, other number-size arrangements can be generated for further testing.*
207+
208+
209+
##### Large number of downloads
210+
211+
212+
177213
### What file types and scenarios are left out?
178214

179215
Anything not included in the section above describing what is currently covered is by implication excluded from these tests.

‎create-files.py

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import random
5+
import string
6+
import argparse
7+
8+
QUANTITY = 1000
9+
FILE_NAME_LENGTH = 10
10+
FILE_SIZE = 1 # 1 Byte
11+
ROOT_NAME = "1000-1B"
12+
SPECIAL_FILES_ROOT = "test-tree/special-files/"
13+
14+
15+
def random_string(length=FILE_NAME_LENGTH):
16+
"Generate random string of specified length"
17+
return "".join(random.choices(string.ascii_lowercase, k=length))
18+
19+
20+
def parse_cli():
21+
"""Prepare parser"""
22+
parser = argparse.ArgumentParser(prog="create-files", description="Generate files")
23+
parser.add_argument("--quantity", help="Number of files to be generated", type=int)
24+
parser.add_argument("--size", help="Size of each file to be generated", type=int)
25+
parser.add_argument("--root-name", help="Download zip files for testing")
26+
return parser.parse_args()
27+
28+
29+
def write_file(path, size):
30+
"""Write file of {size} to {path}"""
31+
with open(SPECIAL_FILES_ROOT + "/" + path, "wb") as out:
32+
out.seek((size) - 1)
33+
out.write(b"\0")
34+
35+
36+
def check_path(path):
37+
"""Make sure given path exists within special files directory"""
38+
if not os.path.exists(SPECIAL_FILES_ROOT):
39+
os.makedirs(SPECIAL_FILES_ROOT)
40+
if not os.path.exists(SPECIAL_FILES_ROOT + "/" + path):
41+
os.makedirs(SPECIAL_FILES_ROOT + "/" + path)
42+
43+
44+
def main():
45+
global QUANTITY
46+
global FILE_SIZE
47+
global ROOT_NAME
48+
args = parse_cli()
49+
if args.quantity:
50+
QUANTITY = args.quantity
51+
if args.size:
52+
FILE_SIZE = args.size
53+
if args.root_name:
54+
ROOT_NAME = args.root_name
55+
check_path(ROOT_NAME)
56+
for _ in range(0, QUANTITY):
57+
write_file(ROOT_NAME + "/" + random_string(), FILE_SIZE)
58+
59+
60+
if __name__ == "__main__":
61+
main()

0 commit comments

Comments
 (0)
Please sign in to comment.