DataStoreMock
In-memory stand-in for a Roblox GlobalDataStore used by tests. It faithfully
round-trips values through a deep copy (mimicking JSON serialization, so aliasing
bugs surface the same way they would against a real datastore) and lets tests inject
failures such as the 509 Personal-RCC block.
It is a first-class citizen of the datastore package: the DataStorePromises wrappers
accept it anywhere a real datastore Instance is expected via
DataStoreMock.isDataStoreMock.
local store = DataStoreMock.new("PlayerData", "SaveData")
store:SetRaw("key", { coins = 5 })
-- Simulate Roblox datastores being down
store:FailAllRequests(DataStoreMock.OPERATION_NOT_ALLOWED_509)
Properties
OPERATION_NOT_ALLOWED_509
DataStoreMock.OPERATION_NOT_ALLOWED_509: stringThe error Roblox raises when datastore operations run on a Personal RCC. This is the real-world failure that motivated the mock.
Functions
isDataStoreMock
DataStoreMock.isDataStoreMock(value: any) → boolean
Returns whether the given value is a DataStoreMock. Used by DataStorePromises so the
mock can stand in for a real datastore Instance.
new
Constructs a new DataStoreMock.
SetYieldTime
Sets how long (in seconds) each request yields before completing, to mimic real datastore latency. Defaults to 0 (no yield) so tests stay fast.
SetErrorInjector
DataStoreMock.SetErrorInjector(errorInjector: ((ErrorInjectorContext) → string?)?) → ()Injects a callback consulted before every request. Returning a string from the callback makes that request throw the string as its error; returning nil lets the request proceed.
FailAllRequests
DataStoreMock.FailAllRequests(errorMessage: string?--
Defaults to the 509 Personal-RCC error
) → ()Makes every subsequent request throw the given error until DataStoreMock.StopFailing is called. Simulates a total datastore outage.
FailNextRequests
DataStoreMock.FailNextRequests() → ()
Makes the next count requests throw the given error, then recover. Simulates a
transient outage that the retry logic is expected to survive.
StopFailing
Clears any injected failures.