mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-26 10:37:04 -06:00
Merge pull request #7336 from dolthub/zachmu/event-error
Fixed spurious error message for event scheduling when the dolt_schem…
This commit is contained in:
@@ -66,6 +66,7 @@ require (
|
||||
github.com/jmoiron/sqlx v1.3.4
|
||||
github.com/kch42/buzhash v0.0.0-20160816060738-9bdec3dec7c6
|
||||
github.com/kylelemons/godebug v1.1.0
|
||||
github.com/lib/pq v1.10.9
|
||||
github.com/oracle/oci-go-sdk/v65 v65.55.0
|
||||
github.com/prometheus/client_golang v1.13.0
|
||||
github.com/rs/zerolog v1.28.0
|
||||
@@ -128,7 +129,6 @@ require (
|
||||
github.com/klauspost/compress v1.10.5 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.0.12 // indirect
|
||||
github.com/lestrrat-go/strftime v1.0.4 // indirect
|
||||
github.com/lib/pq v1.10.9 // indirect
|
||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
|
||||
|
||||
@@ -463,7 +463,6 @@ github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc/go.mod h1:kopu
|
||||
github.com/lestrrat-go/strftime v1.0.4 h1:T1Rb9EPkAhgxKqbcMIPguPq8glqXTA1koF8n9BHElA8=
|
||||
github.com/lestrrat-go/strftime v1.0.4/go.mod h1:E1nN3pCbtMSu1yjSVeyuRFVm/U0xoR76fd03sz+Qz4g=
|
||||
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/lib/pq v1.10.0 h1:Zx5DJFEYQXio93kgXnQ09fXNiUKsqv4OUEu2UtGcB1E=
|
||||
github.com/lib/pq v1.10.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
||||
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
|
||||
@@ -1353,6 +1353,12 @@ func (db Database) GetEvents(ctx *sql.Context) (events []sql.EventDefinition, to
|
||||
|
||||
// NeedsToReloadEvents implements sql.EventDatabase.
|
||||
func (db Database) NeedsToReloadEvents(ctx *sql.Context, token interface{}) (bool, error) {
|
||||
// A nil token means no events in this db. If the dolt_schemas table doesn't exist, it will have a zero hash below
|
||||
// as well, meaning we don't reload events in that case.
|
||||
if token == nil {
|
||||
token = hash.Hash{}
|
||||
}
|
||||
|
||||
hash, ok := token.(hash.Hash)
|
||||
if !ok {
|
||||
return false, fmt.Errorf("expected token to be hash.Hash, but received %T", token)
|
||||
|
||||
@@ -15,11 +15,16 @@
|
||||
package sqle
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dtestutils"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table/editor"
|
||||
)
|
||||
|
||||
func testKeyFunc(t *testing.T, keyFunc func(string) (bool, string), testVal string, expectedIsKey bool, expectedDBName string) {
|
||||
@@ -36,3 +41,71 @@ func TestIsKeyFuncs(t *testing.T) {
|
||||
testKeyFunc(t, dsess.IsHeadKey, "dolt_working", false, "")
|
||||
testKeyFunc(t, dsess.IsWorkingKey, "dolt_working", true, "dolt")
|
||||
}
|
||||
|
||||
func TestNeedsToReloadEvents(t *testing.T) {
|
||||
dEnv := dtestutils.CreateTestEnv()
|
||||
tmpDir, err := dEnv.TempTableFilesDir()
|
||||
require.NoError(t, err)
|
||||
opts := editor.Options{Deaf: dEnv.DbEaFactory(), Tempdir: tmpDir}
|
||||
|
||||
timestamp := time.Now().Truncate(time.Minute).UTC()
|
||||
|
||||
db, err := NewDatabase(context.Background(), "dolt", dEnv.DbData(), opts)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, ctx, err := NewTestEngine(dEnv, context.Background(), db)
|
||||
require.NoError(t, err)
|
||||
|
||||
var token any
|
||||
|
||||
t.Run("empty schema table doesn't need to be reloaded", func(t *testing.T) {
|
||||
needsReload, err := db.NeedsToReloadEvents(ctx, token)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, needsReload)
|
||||
})
|
||||
|
||||
eventDefn := `CREATE EVENT testEvent
|
||||
ON SCHEDULE
|
||||
EVERY 1 DAY
|
||||
STARTS now()
|
||||
DO
|
||||
BEGIN
|
||||
CALL archive_order_history(DATE_SUB(CURDATE(), INTERVAL 1 YEAR));
|
||||
END`
|
||||
|
||||
err = db.addFragToSchemasTable(ctx, "event", "testEvent", eventDefn, timestamp, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("events need to be reloaded after addition", func(t *testing.T) {
|
||||
needsReload, err := db.NeedsToReloadEvents(ctx, token)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, needsReload)
|
||||
})
|
||||
|
||||
_, token, err = db.GetEvents(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("events do not need to be reloaded after no change", func(t *testing.T) {
|
||||
needsReload, err := db.NeedsToReloadEvents(ctx, token)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, needsReload)
|
||||
})
|
||||
|
||||
err = db.dropFragFromSchemasTable(ctx, "event", "testEvent", nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("events need to be reloaded after dropping one", func(t *testing.T) {
|
||||
needsReload, err := db.NeedsToReloadEvents(ctx, token)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, needsReload)
|
||||
})
|
||||
|
||||
_, token, err = db.GetEvents(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("events do not need to be reloaded after no change", func(t *testing.T) {
|
||||
needsReload, err := db.NeedsToReloadEvents(ctx, token)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, needsReload)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func TestProceduresMigration(t *testing.T) {
|
||||
|
||||
timestamp := time.Now().Truncate(time.Minute).UTC()
|
||||
|
||||
ctx, db := newDatabase(t, dEnv, opts, timestamp)
|
||||
ctx, db := newDatabaseWithProcedures(t, dEnv, opts, timestamp)
|
||||
|
||||
t.Run("test migration logic", func(t *testing.T) {
|
||||
// Call the logic to migrate it to the latest schema
|
||||
@@ -102,7 +102,7 @@ func TestProceduresMigration(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func newDatabase(t *testing.T, dEnv *env.DoltEnv, opts editor.Options, timestamp time.Time) (*sql.Context, *Database) {
|
||||
func newDatabaseWithProcedures(t *testing.T, dEnv *env.DoltEnv, opts editor.Options, timestamp time.Time) (*sql.Context, *Database) {
|
||||
db, err := NewDatabase(context.Background(), "dolt", dEnv.DbData(), opts)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user