mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-05 23:13:09 +00:00
* setting up * Implements timer utility * applies async and cancellation to timer loop * Sets up mocktimer and mockblockstore to set up first maintenance module test * wip: first test that calls blockChecker * wip: adding user type to timer callback * Chronicles doesn't like type-arguments? Disables logging in timer module for now * Implementing block check test for blockMaintainer module * Sets up additional tests for blockmaintainer * Removes generic from timer module. Implements numberOfBlocks per interval in blockMaintainer. * Implements blockMaintainer * Sets up tests for blockChecker * Some comments by Mark * Cleanup repostore tests * Setting up the use of std/times for block TTL tracking * repostore adds expiration timestamp * Defaults the repostore clock to the system clock * Applies updates to repostore interface. * Implements retrieving of block expiration information from repostore * Sets up tests for maintenance module behavior * Implements block maintenance module * Wires maintenance module into codex. Sets up integration tests for block expiration * Sets up test for missing behavior: removing timestamp metadata on block delete * Implements removing of expiration metadata in repoStore * Fixes integration tests for block expiration * Adds block expiration tests to integration test run * Handled some comments by Dmitriy * Review comment by Dmitriy: Removes seq[cid] from runBlockCheck * Review comment by Dmitriy: Moves key formatting methods to keyutils. * Review comment by Dmitriy: Encodes durations using chronos * Fixes conversion of TTL type in conf. * Review comments by Dmitriy * Adds unit tests for keyUtils. * Adds test coverage for exception in maintenance module
78 lines
1.8 KiB
Nim
78 lines
1.8 KiB
Nim
import std/osproc
|
|
import std/os
|
|
import std/httpclient
|
|
import std/strutils
|
|
import std/times
|
|
|
|
import pkg/chronos
|
|
import ../ethertest
|
|
import ../contracts/time
|
|
import ../codex/helpers/eventually
|
|
import ./nodes
|
|
import ./tokens
|
|
|
|
ethersuite "Node block expiration tests":
|
|
|
|
var node: NodeProcess
|
|
var baseurl: string
|
|
|
|
let dataDir = getTempDir() / "Codex1"
|
|
let content = "test file content"
|
|
|
|
setup:
|
|
baseurl = "http://localhost:8080/api/codex/v1"
|
|
|
|
teardown:
|
|
node.stop()
|
|
|
|
dataDir.removeDir()
|
|
|
|
proc startTestNode(blockTtlSeconds: int) =
|
|
node = startNode([
|
|
"--api-port=8080",
|
|
"--data-dir=" & dataDir,
|
|
"--nat=127.0.0.1",
|
|
"--disc-ip=127.0.0.1",
|
|
"--disc-port=8090",
|
|
"--block-ttl=" & $blockTtlSeconds,
|
|
"--block-mi=3",
|
|
"--block-mn=10"
|
|
], debug = false)
|
|
|
|
proc uploadTestFile(): string =
|
|
let client = newHttpClient()
|
|
let uploadUrl = baseurl & "/upload"
|
|
let uploadResponse = client.post(uploadUrl, content)
|
|
check uploadResponse.status == "200 OK"
|
|
client.close()
|
|
uploadResponse.body
|
|
|
|
proc downloadTestFile(contentId: string): Response =
|
|
let client = newHttpClient(timeout=3000)
|
|
let downloadUrl = baseurl & "/download/" & contentId
|
|
let content = client.get(downloadUrl)
|
|
client.close()
|
|
content
|
|
|
|
test "node retains not-expired file":
|
|
startTestNode(blockTtlSeconds = 60 * 60 * 1)
|
|
|
|
let contentId = uploadTestFile()
|
|
|
|
await sleepAsync(10 * 1000)
|
|
|
|
let response = downloadTestFile(contentId)
|
|
check:
|
|
response.status == "200 OK"
|
|
response.body == content
|
|
|
|
test "node deletes expired file":
|
|
startTestNode(blockTtlSeconds = 5)
|
|
|
|
let contentId = uploadTestFile()
|
|
|
|
await sleepAsync(10 * 1000)
|
|
|
|
expect TimeoutError:
|
|
discard downloadTestFile(contentId)
|