Compare commits

...

14 Commits

Author SHA1 Message Date
Arnaud
5943738212
Merge pull request #19 from logos-storage/build/dev-env-gotestsum-and-makefile
Build: small updates to dev env: debugging, gotestsum and makefile
2025-12-11 06:08:14 +01:00
Marcin Czenko
2cd2df0beb
Updates README 2025-11-28 01:48:34 +01:00
Marcin Czenko
d8b21f2087
Installs gotestsum on the CI 2025-11-28 01:16:08 +01:00
Marcin Czenko
316d2bde6c
adds make target to build the lib with debug API 2025-11-28 01:16:08 +01:00
Marcin Czenko
be94580b23
adds extra make target to Makefile allowing you to pass parameters to go test 2025-11-28 01:16:08 +01:00
Marcin Czenko
99cffb1829
adds possibility to run selected tests with "make test <name>" 2025-11-28 01:16:08 +01:00
Marcin Czenko
79d9643745
adds launch configuration for more convenient debugging 2025-11-28 01:16:08 +01:00
Marcin Czenko
56914260a0 uses Nat: "none" in recently added tests 2025-11-27 22:06:05 +01:00
Arnaud
5ba9d94ecf
Update changelog 2025-11-14 06:00:10 +01:00
Arnaud
8026f3fd8d
Merge pull request #16 from codex-storage/fix/configuration-duration
fix: fix configuration types
2025-11-14 08:22:05 +04:00
Arnaud
017b032d84
Bump nim codex and fix configuration 2025-11-14 05:01:45 +01:00
Arnaud
1cf7fe4407
Merge pull request #15 from codex-storage/fix/prevent-datastore-lock
fix: bump nim codex to prevent datastore lock when closing the Codex client
2025-11-14 07:42:49 +04:00
Arnaud
429d076008
Bump nim codex to prevent datastore lock when closing the Codex client 2025-11-14 04:24:16 +01:00
Arnaud
c47e7ae49d
Update changelog 2025-11-11 11:46:18 +01:00
10 changed files with 228 additions and 8 deletions

View File

@ -46,5 +46,8 @@ jobs:
- name: Build codex go
run: make
- name: Install gotestsum
run: go install gotest.tools/gotestsum@latest
- name: Go test
run: make test

77
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,77 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug Current Test",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${fileDirname}",
"args": ["-test.v", "-test.run", "^${selectedText}$"],
"env": {
"CGO_ENABLED": "1"
}
},
{
"name": "Debug Current Test Function",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${fileDirname}",
"env": {
"CGO_ENABLED": "1"
}
},
{
"name": "Debug All Tests in Current File",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${fileDirname}",
"args": ["-test.v"],
"env": {
"CGO_ENABLED": "1"
}
},
{
"name": "Debug All Tests in Current Package",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${fileDirname}",
"args": ["-test.v", "-count=1"],
"env": {
"CGO_ENABLED": "1"
}
},
{
"name": "Debug Codex Tests",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${workspaceFolder}/codex",
"args": ["-test.v"],
"env": {
"CGO_ENABLED": "1"
}
},
{
"name": "Debug Specific Test (e.g., TestUpload)",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${workspaceFolder}/codex",
"args": [
"-test.v",
"-test.run",
"TestUpload"
],
"env": {
"CGO_ENABLED": "1"
}
}
]
}

View File

@ -1,3 +1,15 @@
## v0.0.28 (2025-11-14)
### Notes
- fix: bump nim codex to prevent datastore lock when closing the Codex client
- fix: configuration duration for block-ttl, block-mi and int for num-threads
## v0.0.27 (2025-11-11)
### Notes
- Enhance release note in
- Bump nim-codex to prototype release branch
## v0.0.26 (2025-11-03)
### Notes

View File

@ -23,13 +23,24 @@ libcodex:
@echo "Building libcodex..."
@$(MAKE) -C $(NIM_CODEX_DIR) libcodex
libcodex-with-debug-api:
@echo "Building libcodex..."
@$(MAKE) -C $(NIM_CODEX_DIR) libcodex CODEX_LIB_PARAMS="-d:codex_enable_api_debug_peers"
build:
@echo "Building Codex Go Bindings..."
CGO_ENABLED=1 CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" go build -o codex-go ./codex
test:
@echo "Running tests..."
CGO_ENABLED=1 CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" GOTESTFLAGS="-timeout=2m" go test ./...
CGO_ENABLED=1 CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" GOTESTFLAGS="-timeout=2m" gotestsum --packages="./..." -f testname -- $(if $(filter-out test,$(MAKECMDGOALS)),-run "$(filter-out test,$(MAKECMDGOALS))")
test-with-params:
@echo "Running tests..."
CGO_ENABLED=1 CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" GOTESTFLAGS="-timeout=2m" gotestsum --packages="./..." -f testname -- $(ARGS)
%:
@:
clean:
@echo "Cleaning up..."

View File

@ -78,22 +78,63 @@ Follow these steps to install and set up the module:
1. Make sure your system has the [prerequisites](https://github.com/codex-storage/nim-codex) to run a local Codex node.
2. Fetch the dependencies:
```
```sh
make update
```
3. Build the library:
```
```sh
make libcodex
```
You can pass flags to the Codex building step by using `CODEX_LIB_PARAMS`. For example,
if you want to enable debug API for peers, you can build the library using:
```
```sh
CODEX_LIB_PARAMS="-d:codex_enable_api_debug_peers=true" make libcodex
```
or you can use a convenience `libcodex-with-debug-api` make target:
```sh
make libcodex-with-debug-api
```
To run the test, you have to make sure you have `gotestsum` installed on your system, e.g.:
```sh
go install gotest.tools/gotestsum@latest
```
Then you can run the tests as follows.
To run all the tests:
```sh
make test
```
To run selected test only:
```sh
make test "TestDownloadManifest$"
```
> We use `$` to make sure we run only the `TestDownloadManifest` test.
> Without `$` we would run all the tests starting with `TestDownloadManifest` and
> so also `TestDownloadManifestWithNotExistingCid`
>
If you need to pass more arguments to the underlying `go test` (`gotestsum` passes
everything after `--` to `go test`), you can use: `test-with-params` make target, e.g.:
```sh
make test-with-params ARGS='-run "TestDownloadManifest$$" -count=2'
```
> Here, we use double escape `$$` instead of just `$`, otherwise make
> will interpret `$` as a make variable inside `ARGS`.
Now the module is ready for use in your project.
The release process is defined [here](./RELEASE.md).

View File

@ -159,12 +159,12 @@ type Config struct {
// Default block timeout in seconds - 0 disables the ttl
// Default: 30 days
BlockTtl int `json:"block-ttl,omitempty"`
BlockTtl string `json:"block-ttl,omitempty"`
// Time interval in seconds - determines frequency of block
// maintenance cycle: how often blocks are checked for expiration and cleanup
// Default: 10 minutes
BlockMaintenanceInterval int `json:"block-mi,omitempty"`
BlockMaintenanceInterval string `json:"block-mi,omitempty"`
// Number of blocks to check every maintenance cycle
// Default: 1000

View File

@ -1,6 +1,8 @@
package codex
import "testing"
import (
"testing"
)
func TestCodexVersion(t *testing.T) {
config := defaultConfigHelper(t)
@ -89,3 +91,64 @@ func TestStorageQuota(t *testing.T) {
t.Fatal("expected codex node to be created")
}
}
func TestCreateAndDestroyMultipleInstancesWithSameDatadir(t *testing.T) {
datadir := t.TempDir()
config := Config{
DataDir: datadir,
LogFormat: LogFormatNoColors,
MetricsEnabled: false,
BlockRetries: 5,
Nat: "none",
}
for range 2 {
node, err := New(config)
if err != nil {
t.Fatalf("Failed to create Codex node: %v", err)
}
if err := node.Start(); err != nil {
t.Fatalf("Failed to start Codex node: %v", err)
}
if err := node.Stop(); err != nil {
t.Fatalf("Failed to stop Codex node: %v", err)
}
if err := node.Destroy(); err != nil {
t.Fatalf("Failed to stop Codex node after restart: %v", err)
}
}
}
func TestNumThreads(t *testing.T) {
node := newCodexNode(t, Config{
NumThreads: 1,
})
if node == nil {
t.Fatal("expected codex node to be created")
}
}
func TestBlockTtl(t *testing.T) {
node := newCodexNode(t, Config{
BlockTtl: "10H",
})
if node == nil {
t.Fatal("expected codex node to be created")
}
}
func TestBlockMaintenanceInterval(t *testing.T) {
node := newCodexNode(t, Config{
BlockMaintenanceInterval: "10H",
})
if node == nil {
t.Fatal("expected codex node to be created")
}
}

View File

@ -36,6 +36,7 @@ func TestConnectWithAddress(t *testing.T) {
LogFormat: LogFormatNoColors,
MetricsEnabled: false,
DiscoveryPort: 8090,
Nat: "none",
})
if err != nil {
t.Fatalf("Failed to create codex1: %v", err)

View File

@ -47,6 +47,18 @@ func newCodexNode(t *testing.T, opts ...Config) *CodexNode {
if c.StorageQuota != 0 {
config.StorageQuota = c.StorageQuota
}
if c.NumThreads != 0 {
config.NumThreads = c.NumThreads
}
if c.BlockTtl != "" {
config.BlockTtl = c.BlockTtl
}
if c.BlockMaintenanceInterval != "" {
config.BlockMaintenanceInterval = c.BlockMaintenanceInterval
}
}
node, err := New(config)

2
vendor/nim-codex vendored

@ -1 +1 @@
Subproject commit 5a227dbb561672667c5c0285a417175b5004ddf7
Subproject commit 2b9fc1eb554e5eee43b8a815084fb8c61687ada9