Allowing a period parameter to be passed into event executor to override the default loop period (30s) and using for BATS tests

This commit is contained in:
Jason Fulghum
2023-09-26 15:40:12 -07:00
parent ab44211a85
commit c9d2c73a4d
2 changed files with 22 additions and 1 deletions

View File

@@ -16,8 +16,10 @@ package engine
import (
"context"
"github.com/sirupsen/logrus"
"os"
"runtime"
"strconv"
"strings"
gms "github.com/dolthub/go-mysql-server"
@@ -354,7 +356,21 @@ func configureEventScheduler(config *SqlEngineConfig, engine *gms.Engine, sessFa
}, nil
}
return engine.InitializeEventScheduler(getCtxFunc, config.EventSchedulerStatus)
// A hidden env var allows overriding the event scheduler period for testing. This option is not
// exposed via configuration because we do not want to encourage customers to use it. If the value
// is equal to or less than 0, then the period is ignored and the default period, 30s, is used.
eventSchedulerPeriod := 0
eventSchedulerPeriodEnvVar := "DOLT_EVENT_SCHEDULER_PERIOD"
if s, ok := os.LookupEnv(eventSchedulerPeriodEnvVar); ok {
i, err := strconv.Atoi(s)
if err != nil {
logrus.Warnf("unable to parse value '%s' from env var '%s' as an integer", s, eventSchedulerPeriodEnvVar)
} else {
logrus.Warnf("overriding Dolt event scheduler period to %d seconds", i)
eventSchedulerPeriod = i
}
}
return engine.InitializeEventScheduler(getCtxFunc, config.EventSchedulerStatus, eventSchedulerPeriod)
}
// sqlContextFactory returns a contextFactory that creates a new sql.Context with the initial database provided

View File

@@ -6,7 +6,12 @@ make_test_repo_and_start_server() {
rm -rf ./"$1"
mkdir "$1"
cd "$1"
# Override the default event scheduler period (30s) and set it to 1s so that we can run
# tests faster, without having to wait for the default 30s period to elapse several times.
export DOLT_EVENT_SCHEDULER_PERIOD=1
start_sql_server
dolt sql-client -P $PORT -u dolt --use-db information_schema -q "CREATE DATABASE repo1;"
dolt sql-client -P $PORT -u dolt --use-db repo1 -q "CREATE TABLE totals (id int PRIMARY KEY AUTO_INCREMENT, int_col int);"
dolt sql-client -P $PORT -u dolt --use-db repo1 -q "call dolt_commit('-Am', 'creating table');"