Skip to content

Commit

Permalink
chore: Simplification of store legacy code (#2931)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivansete-status authored Jul 30, 2024
1 parent aed2a11 commit d4e8a0d
Show file tree
Hide file tree
Showing 19 changed files with 110 additions and 1,071 deletions.
1 change: 0 additions & 1 deletion tests/all_tests_waku.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import
./waku_archive_legacy/test_driver_queue,
./waku_archive_legacy/test_driver_sqlite_query,
./waku_archive_legacy/test_driver_sqlite,
./waku_archive_legacy/test_retention_policy,
./waku_archive_legacy/test_waku_archive

const os* {.strdefine.} = ""
Expand Down
29 changes: 24 additions & 5 deletions tests/waku_archive_legacy/test_driver_postgres.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import std/[sequtils, options], testutils/unittests, chronos
import
waku/waku_archive_legacy,
waku/waku_archive_legacy/driver/postgres_driver,
waku/waku_archive/driver/postgres_driver as new_postgres_driver,
waku/waku_core,
waku/waku_core/message/digest,
../testlib/wakucore,
../testlib/testasync,
../testlib/postgres_legacy
../testlib/postgres_legacy,
../testlib/postgres as new_postgres

proc computeTestCursor(pubsubTopic: PubsubTopic, message: WakuMessage): ArchiveCursor =
ArchiveCursor(
Expand All @@ -21,22 +23,39 @@ proc computeTestCursor(pubsubTopic: PubsubTopic, message: WakuMessage): ArchiveC

suite "Postgres driver":
## Unique driver instance
var driver {.threadvar.}: PostgresDriver
var driver {.threadvar.}: postgres_driver.PostgresDriver

## We need to artificially create an instance of the "newDriver"
## because this is the only one in charge of creating partitions
## We will clean legacy store soon and this file will get removed.
var newDriver {.threadvar.}: new_postgres_driver.PostgresDriver

asyncSetup:
let driverRes = await newTestPostgresDriver()
let driverRes = await postgres_legacy.newTestPostgresDriver()
if driverRes.isErr():
assert false, driverRes.error

driver = postgres_driver.PostgresDriver(driverRes.get())

let newDriverRes = await new_postgres.newTestPostgresDriver()
if driverRes.isErr():
assert false, driverRes.error

driver = PostgresDriver(driverRes.get())
newDriver = new_postgres_driver.PostgresDriver(newDriverRes.get())

asyncTeardown:
let resetRes = await driver.reset()
var resetRes = await driver.reset()
if resetRes.isErr():
assert false, resetRes.error

(await driver.close()).expect("driver to close")

resetRes = await newDriver.reset()
if resetRes.isErr():
assert false, resetRes.error

(await newDriver.close()).expect("driver to close")

asyncTest "Asynchronous queries":
var futures = newSeq[Future[ArchiveDriverResult[void]]](0)

Expand Down
39 changes: 31 additions & 8 deletions tests/waku_archive_legacy/test_driver_postgres_query.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import
waku/waku_archive_legacy,
waku/waku_archive_legacy/driver as driver_module,
waku/waku_archive_legacy/driver/postgres_driver,
waku/waku_archive/driver/postgres_driver as new_postgres_driver,
waku/waku_core,
waku/waku_core/message/digest,
../testlib/common,
../testlib/wakucore,
../testlib/testasync,
../testlib/postgres_legacy
../testlib/postgres_legacy,
../testlib/postgres as new_postgres,
../testlib/testutils

logScope:
topics = "test archive postgres driver"
Expand All @@ -36,22 +39,39 @@ proc computeTestCursor(pubsubTopic: PubsubTopic, message: WakuMessage): ArchiveC

suite "Postgres driver - queries":
## Unique driver instance
var driver {.threadvar.}: PostgresDriver
var driver {.threadvar.}: postgres_driver.PostgresDriver

## We need to artificially create an instance of the "newDriver"
## because this is the only one in charge of creating partitions
## We will clean legacy store soon and this file will get removed.
var newDriver {.threadvar.}: new_postgres_driver.PostgresDriver

asyncSetup:
let driverRes = await newTestPostgresDriver()
let driverRes = await postgres_legacy.newTestPostgresDriver()
if driverRes.isErr():
assert false, driverRes.error

driver = postgres_driver.PostgresDriver(driverRes.get())

let newDriverRes = await new_postgres.newTestPostgresDriver()
if driverRes.isErr():
assert false, driverRes.error

driver = PostgresDriver(driverRes.get())
newDriver = new_postgres_driver.PostgresDriver(newDriverRes.get())

asyncTeardown:
let resetRes = await driver.reset()
var resetRes = await driver.reset()
if resetRes.isErr():
assert false, resetRes.error

(await driver.close()).expect("driver to close")

resetRes = await newDriver.reset()
if resetRes.isErr():
assert false, resetRes.error

(await newDriver.close()).expect("driver to close")

asyncTest "no content topic":
## Given
const contentTopic = "test-content-topic"
Expand Down Expand Up @@ -1790,7 +1810,8 @@ suite "Postgres driver - queries":
check:
filteredMessages.len == 0

asyncTest "Get oldest and newest message timestamp":
xasyncTest "Get oldest and newest message timestamp":
## This test no longer makes sense because that will always be controlled by the newDriver
const contentTopic = "test-content-topic"

let timeOrigin = now()
Expand Down Expand Up @@ -1842,7 +1863,8 @@ suite "Postgres driver - queries":
assert res.isOk(), res.error
assert res.get() == newestTime, "Failed to retrieve the newest timestamp"

asyncTest "Delete messages older than certain timestamp":
xasyncTest "Delete messages older than certain timestamp":
## This test no longer makes sense because that will always be controlled by the newDriver
const contentTopic = "test-content-topic"

let timeOrigin = now()
Expand Down Expand Up @@ -1884,7 +1906,8 @@ suite "Postgres driver - queries":
assert res.isOk(), res.error
assert res.get() == 3, "Failed to retrieve the # of messages after deletion"

asyncTest "Keep last n messages":
xasyncTest "Keep last n messages":
## This test no longer makes sense because that will always be controlled by the newDriver
const contentTopic = "test-content-topic"

let timeOrigin = now()
Expand Down
169 changes: 0 additions & 169 deletions tests/waku_archive_legacy/test_retention_policy.nim

This file was deleted.

10 changes: 1 addition & 9 deletions waku/factory/node_factory.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import
../waku_archive/retention_policy/builder as policy_builder,
../waku_archive/driver as driver,
../waku_archive/driver/builder as driver_builder,
../waku_archive_legacy/retention_policy as legacy_policy,
../waku_archive_legacy/retention_policy/builder as legacy_policy_builder,
../waku_archive_legacy/driver as legacy_driver,
../waku_archive_legacy/driver/builder as legacy_driver_builder,
../waku_store,
Expand Down Expand Up @@ -232,13 +230,7 @@ proc setupProtocols(
if archiveDriverRes.isErr():
return err("failed to setup legacy archive driver: " & archiveDriverRes.error)

let retPolicyRes =
legacy_policy.RetentionPolicy.new(conf.storeMessageRetentionPolicy)
if retPolicyRes.isErr():
return err("failed to create retention policy: " & retPolicyRes.error)

let mountArcRes =
node.mountLegacyArchive(archiveDriverRes.get(), retPolicyRes.get())
let mountArcRes = node.mountLegacyArchive(archiveDriverRes.get())
if mountArcRes.isErr():
return err("failed to mount waku legacy archive protocol: " & mountArcRes.error)

Expand Down
10 changes: 2 additions & 8 deletions waku/node/waku_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -703,17 +703,11 @@ proc mountArchive*(
return ok()

proc mountLegacyArchive*(
node: WakuNode,
driver: waku_archive_legacy.ArchiveDriver,
retentionPolicy = none(waku_archive_legacy.RetentionPolicy),
node: WakuNode, driver: waku_archive_legacy.ArchiveDriver
): Result[void, string] =
node.wakuLegacyArchive = waku_archive_legacy.WakuArchive.new(
driver = driver, retentionPolicy = retentionPolicy
).valueOr:
node.wakuLegacyArchive = waku_archive_legacy.WakuArchive.new(driver = driver).valueOr:
return err("error in mountLegacyArchive: " & error)

node.wakuLegacyArchive.start()

return ok()

## Legacy Waku Store
Expand Down
5 changes: 2 additions & 3 deletions waku/waku_archive_legacy.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import
./waku_archive_legacy/common,
./waku_archive_legacy/archive,
./waku_archive_legacy/driver,
./waku_archive_legacy/retention_policy
./waku_archive_legacy/driver

export common, archive, driver, retention_policy
export common, archive, driver
Loading

0 comments on commit d4e8a0d

Please sign in to comment.