MCPcopy
hub / github.com/HelloZeroNet/ZeroNet / testSparseFile

Method testSparseFile

plugins/Bigfile/Test/TestBigfile.py:67–93  ·  view source on GitHub ↗
(self, site)

Source from the content-addressed store, hash-verified

65 assert "Invalid hash" in str(err.value)
66
67 def testSparseFile(self, site):
68 inner_path = "sparsefile"
69
70 # Create a 100MB sparse file
71 site.storage.createSparseFile(inner_path, 100 * 1024 * 1024)
72
73 # Write to file beginning
74 s = time.time()
75 f = site.storage.write("%s|%s-%s" % (inner_path, 0, 1024 * 1024), b"hellostart" * 1024)
76 time_write_start = time.time() - s
77
78 # Write to file end
79 s = time.time()
80 f = site.storage.write("%s|%s-%s" % (inner_path, 99 * 1024 * 1024, 99 * 1024 * 1024 + 1024 * 1024), b"helloend" * 1024)
81 time_write_end = time.time() - s
82
83 # Verify writes
84 f = site.storage.open(inner_path)
85 assert f.read(10) == b"hellostart"
86 f.seek(99 * 1024 * 1024)
87 assert f.read(8) == b"helloend"
88 f.close()
89
90 site.storage.delete(inner_path)
91
92 # Writing to end shold not take much longer, than writing to start
93 assert time_write_end <= max(0.1, time_write_start * 1.1)
94
95 def testRangedFileRequest(self, file_server, site, site_temp):
96 inner_path = self.createBigfile(site)

Callers

nothing calls this directly

Calls 7

createSparseFileMethod · 0.80
openMethod · 0.80
writeMethod · 0.45
readMethod · 0.45
seekMethod · 0.45
closeMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected