Skip to content
This repository was archived by the owner on Sep 5, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-go-unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ jobs:
cache-dependency-path: go.sum

- name: Run Unit Tests
run: go test -race -v ./unit_test/...
run: go test -race -v . ./unit_test/...
8 changes: 7 additions & 1 deletion engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,18 @@ var (
// This ensures that we only have one instance of modusDB in this process.
singleton atomic.Bool

ErrSingletonOnly = errors.New("only one modusDB engine is supported")
ErrSingletonOnly = errors.New("only one instance of modusDB can exist in a process")
ErrEmptyDataDir = errors.New("data directory is required")
ErrClosedEngine = errors.New("modusDB engine is closed")
ErrNonExistentDB = errors.New("namespace does not exist")
)

// ResetSingleton resets the singleton state for testing purposes.
// This should ONLY be called during testing, typically in cleanup functions.
func ResetSingleton() {
singleton.Store(false)
}

// Engine is an instance of modusDB.
// For now, we only support one instance of modusDB per process.
type Engine struct {
Expand Down
6 changes: 1 addition & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/hypermodeinc/modusgraph

go 1.24.1

toolchain go1.24.2
go 1.24.2

require (
github.com/cavaliergopher/grab/v3 v3.0.1
Expand Down Expand Up @@ -151,5 +149,3 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/dolan-in/dgman/v2 => github.com/matthewmcneely/dgman/v2 v2.0.1
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/dolan-in/dgman/v2 v2.0.0 h1:kMhUo3dYr4SCWJe87cNbBctD5f2fC+pX/cLz52pVYAE=
github.com/dolan-in/dgman/v2 v2.0.0/go.mod h1:JI2D8vtkMBp9Ec8/wBPuJPPT89C+HQnQYb0biuXo4do=
github.com/dolan-in/reflectwalk v1.0.2-0.20210101124621-dc2073a29d71 h1:v3bErDrPApxsyBlz8/8nFTCb7Ai0wecA8TokfEHIQ80=
github.com/dolan-in/reflectwalk v1.0.2-0.20210101124621-dc2073a29d71/go.mod h1:Y9TyDkSL5jQ18ZnDaSxOdCUhbb5SCeamqYFQ7LYxxFs=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
Expand Down Expand Up @@ -388,8 +390,6 @@ github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80/go.mod h1:imJHygn/1
github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/matryer/moq v0.0.0-20200106131100-75d0ddfc0007/go.mod h1:9ELz6aaclSIGnZBoaSLZ3NAl1VTufbOrXBPvtcy6WiQ=
github.com/matthewmcneely/dgman/v2 v2.0.1 h1:rdqClEb0tFd7PhjFfWC9771Z7RiqtoX7GU6IqJbeAfg=
github.com/matthewmcneely/dgman/v2 v2.0.1/go.mod h1:GOuKyhoakfLVKw2xJTazd0rfEeeMF3UB2oejL0xsr30=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
Expand Down
8 changes: 3 additions & 5 deletions unit_test/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ package unit_test

import (
"context"
"fmt"
"testing"

"github.com/dgraph-io/dgo/v240/protos/api"
"github.com/hypermodeinc/modusgraph"
"github.com/stretchr/testify/require"
)

// TestDgraphWithBufconn tests Dgraph operations using bufconn
func TestDgraphWithBufconn(t *testing.T) {
func TestRDF(t *testing.T) {
// Create a new engine - this initializes all the necessary components
engine, err := modusgraph.NewEngine(modusgraph.NewDefaultConfig(t.TempDir()))
require.NoError(t, err)
Expand All @@ -43,7 +41,7 @@ func TestDgraphWithBufconn(t *testing.T) {
txn := client.NewReadOnlyTxn()
resp, err := txn.Query(ctx, "schema {}")
require.NoError(t, err)
fmt.Println("resp", resp)
require.NotEmpty(t, resp.Json)
_ = txn.Discard(ctx)

txn = client.NewTxn()
Expand All @@ -64,7 +62,7 @@ func TestDgraphWithBufconn(t *testing.T) {
// Query to verify the mutation worked
resp, err = txn.Query(ctx, `{ q(func: has(n)) { n } }`)
require.NoError(t, err)
fmt.Println("query after mutation:", resp)
require.NotEmpty(t, resp.Json)
_ = txn.Discard(ctx)

err = client.Alter(context.Background(), &api.Operation{DropAll: true})
Expand Down
3 changes: 3 additions & 0 deletions util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ func CreateTestClient(t *testing.T, uri string) (mg.Client, func()) {
t.Error(err)
}
client.Close()

// Reset the singleton state so the next test can create a new engine
mg.ResetSingleton()
}

return client, cleanup
Expand Down