@quenty/saveslot 2.10.0 → 2.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/package.json +18 -17
- package/src/Client/Binders/HasSaveSlotsClient.spec.lua +4 -14
- package/src/Server/Binders/HasSaveSlots.Code.spec.lua +20 -7
- package/src/Server/Binders/HasSaveSlots.ExportImport.spec.lua +18 -10
- package/src/Server/Binders/HasSaveSlots.PreSelect.spec.lua +21 -33
- package/src/Server/Binders/HasSaveSlots.SharedStore.spec.lua +18 -7
- package/src/Server/Binders/HasSaveSlots.TransferableEphemeral.spec.lua +18 -7
- package/src/Server/Binders/HasSaveSlots.spec.lua +181 -171
- package/src/Server/Cmdr/SaveSlotCmdrService.spec.lua +23 -18
- package/src/Server/HasSaveSlotsDataStore.lua +1 -1
- package/src/Server/OfflineSaveSlots.spec.lua +12 -7
- package/src/Server/{SaveSlotLateSettle.spec.lua → SaveSlotService.LateSettle.spec.lua} +61 -76
- package/src/Server/SaveSlotService.LoadFlow.spec.lua +117 -0
- package/src/Server/SaveSlotService.Overflow.spec.lua +112 -0
- package/src/Server/{SaveSlotPlaytime.spec.lua → SaveSlotService.Playtime.spec.lua} +23 -13
- package/src/Server/SaveSlotService.spec.lua +37 -32
- package/src/Server/SaveSlotSharedDataStoreService.spec.lua +14 -7
- package/src/Shared/Data/SaveSlotData.spec.lua +1 -1
- package/src/Server/SaveSlotLoadFlow.spec.lua +0 -151
- package/src/Server/SaveSlotOverflow.spec.lua +0 -125
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
--!nonstrict
|
|
2
|
-
--[[
|
|
3
|
-
Characterizes the save-slot load flow -- the substore reads HasSaveSlots performs -- driven
|
|
4
|
-
through a mock-injected PlayerDataStoreService. A headless cloud test server has no real Players
|
|
5
|
-
to bind the PlayerBinder to, so these reproduce the load against the same datastore substore
|
|
6
|
-
layout (SaveSlotConstants) with a numeric userId.
|
|
7
|
-
|
|
8
|
-
@class SaveSlotLoadFlow.spec.lua
|
|
9
|
-
]]
|
|
10
|
-
local require = require(script.Parent.loader).load(script)
|
|
11
|
-
|
|
12
|
-
local DataStoreMock = require("DataStoreMock")
|
|
13
|
-
local DataStoreTestUtils = require("DataStoreTestUtils")
|
|
14
|
-
local Jest = require("Jest")
|
|
15
|
-
local Maid = require("Maid")
|
|
16
|
-
local PromiseTestUtils = require("PromiseTestUtils")
|
|
17
|
-
local SaveSlotConstants = require("SaveSlotConstants")
|
|
18
|
-
local ServiceBag = require("ServiceBag")
|
|
19
|
-
|
|
20
|
-
local describe = Jest.Globals.describe
|
|
21
|
-
local expect = Jest.Globals.expect
|
|
22
|
-
local it = Jest.Globals.it
|
|
23
|
-
|
|
24
|
-
local function setup(mock)
|
|
25
|
-
local maid = Maid.new()
|
|
26
|
-
mock = mock or DataStoreMock.new()
|
|
27
|
-
|
|
28
|
-
local serviceBag = maid:Add(ServiceBag.new())
|
|
29
|
-
local playerDataStoreService = serviceBag:GetService(require("PlayerDataStoreService"))
|
|
30
|
-
serviceBag:Init()
|
|
31
|
-
playerDataStoreService:SetRobloxDataStore(mock)
|
|
32
|
-
serviceBag:Start()
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
playerDataStoreService = playerDataStoreService,
|
|
36
|
-
mock = mock,
|
|
37
|
-
destroy = function()
|
|
38
|
-
-- The store the spec loaded is only destroyed by a removal, and a PlayerMock never fires the
|
|
39
|
-
-- real Players.PlayerRemoving, so shut down the way Roblox does or its auto-save loop outlives
|
|
40
|
-
-- this spec and fires inside a later package's window.
|
|
41
|
-
DataStoreTestUtils.awaitServiceShutdown(playerDataStoreService)
|
|
42
|
-
maid:DoCleaning()
|
|
43
|
-
end,
|
|
44
|
-
}
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
local function resolveDataStore(playerDataStoreService, userId)
|
|
48
|
-
local promise = playerDataStoreService:PromiseDataStore(userId)
|
|
49
|
-
if not PromiseTestUtils.awaitSettled(promise, 10) then
|
|
50
|
-
return nil
|
|
51
|
-
end
|
|
52
|
-
local ok, dataStore = promise:Yield()
|
|
53
|
-
if not ok then
|
|
54
|
-
return nil
|
|
55
|
-
end
|
|
56
|
-
return dataStore
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
describe("save slot load flow (healthy datastore)", function()
|
|
60
|
-
it("loads empty slot metadata and no active slot for a fresh user", function()
|
|
61
|
-
local controller = setup()
|
|
62
|
-
|
|
63
|
-
local dataStore = resolveDataStore(controller.playerDataStoreService, 1)
|
|
64
|
-
expect(dataStore).never.toBeNil()
|
|
65
|
-
|
|
66
|
-
local systemStore = dataStore:GetSubStore(SaveSlotConstants.SYSTEM_STORE_KEY)
|
|
67
|
-
local metadataStore = systemStore:GetSubStore(SaveSlotConstants.METADATA_STORE_KEY)
|
|
68
|
-
|
|
69
|
-
local metaPromise = metadataStore:LoadAll({})
|
|
70
|
-
if not PromiseTestUtils.awaitSettled(metaPromise, 10) then
|
|
71
|
-
expect("metadata load hung").toEqual("metadata load settled")
|
|
72
|
-
controller:destroy()
|
|
73
|
-
return
|
|
74
|
-
end
|
|
75
|
-
local metaOk, metadata = metaPromise:Yield()
|
|
76
|
-
expect(metaOk).toEqual(true)
|
|
77
|
-
expect(metadata).toEqual({})
|
|
78
|
-
|
|
79
|
-
local activePromise = systemStore:Load("activeSlotId")
|
|
80
|
-
if not PromiseTestUtils.awaitSettled(activePromise, 10) then
|
|
81
|
-
expect("activeSlotId load hung").toEqual("activeSlotId load settled")
|
|
82
|
-
controller:destroy()
|
|
83
|
-
return
|
|
84
|
-
end
|
|
85
|
-
local activeOk, activeSlotId = activePromise:Yield()
|
|
86
|
-
expect(activeOk).toEqual(true)
|
|
87
|
-
expect(activeSlotId).toEqual(nil)
|
|
88
|
-
|
|
89
|
-
controller:destroy()
|
|
90
|
-
end)
|
|
91
|
-
|
|
92
|
-
it("round-trips a slot's data through the slot substore", function()
|
|
93
|
-
local controller = setup()
|
|
94
|
-
|
|
95
|
-
local dataStore = resolveDataStore(controller.playerDataStoreService, 1)
|
|
96
|
-
expect(dataStore).never.toBeNil()
|
|
97
|
-
|
|
98
|
-
local slotStore = dataStore
|
|
99
|
-
:GetSubStore(SaveSlotConstants.SYSTEM_STORE_KEY)
|
|
100
|
-
:GetSubStore(SaveSlotConstants.SLOT_STORE_KEY)
|
|
101
|
-
:GetSubStore("slot-abc")
|
|
102
|
-
|
|
103
|
-
slotStore:Store("coins", 25)
|
|
104
|
-
|
|
105
|
-
local savePromise = dataStore:Save()
|
|
106
|
-
if not PromiseTestUtils.awaitSettled(savePromise, 10) then
|
|
107
|
-
expect("save hung").toEqual("save settled")
|
|
108
|
-
controller:destroy()
|
|
109
|
-
return
|
|
110
|
-
end
|
|
111
|
-
expect((savePromise:Yield())).toEqual(true)
|
|
112
|
-
|
|
113
|
-
local loadPromise = slotStore:Load("coins")
|
|
114
|
-
if not PromiseTestUtils.awaitSettled(loadPromise, 10) then
|
|
115
|
-
expect("load hung").toEqual("load settled")
|
|
116
|
-
controller:destroy()
|
|
117
|
-
return
|
|
118
|
-
end
|
|
119
|
-
local ok, value = loadPromise:Yield()
|
|
120
|
-
expect(ok).toEqual(true)
|
|
121
|
-
expect(value).toEqual(25)
|
|
122
|
-
|
|
123
|
-
controller:destroy()
|
|
124
|
-
end)
|
|
125
|
-
end)
|
|
126
|
-
|
|
127
|
-
describe("save slot load flow (datastore down)", function()
|
|
128
|
-
it("surfaces an error fast instead of hanging when datastores are down", function()
|
|
129
|
-
local mock = DataStoreMock.new()
|
|
130
|
-
mock:FailAllRequests()
|
|
131
|
-
|
|
132
|
-
local controller = setup(mock)
|
|
133
|
-
|
|
134
|
-
-- The manager hands back a datastore without loading, so this resolves.
|
|
135
|
-
local dataStore = resolveDataStore(controller.playerDataStoreService, 1)
|
|
136
|
-
expect(dataStore).never.toBeNil()
|
|
137
|
-
|
|
138
|
-
local metadataStore =
|
|
139
|
-
dataStore:GetSubStore(SaveSlotConstants.SYSTEM_STORE_KEY):GetSubStore(SaveSlotConstants.METADATA_STORE_KEY)
|
|
140
|
-
|
|
141
|
-
local promise = metadataStore:LoadAll({})
|
|
142
|
-
expect(PromiseTestUtils.awaitSettled(promise, 5)).toEqual(true)
|
|
143
|
-
|
|
144
|
-
if not promise:IsPending() then
|
|
145
|
-
local ok = promise:Yield()
|
|
146
|
-
expect(ok).toEqual(false)
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
controller:destroy()
|
|
150
|
-
end)
|
|
151
|
-
end)
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
--!nonstrict
|
|
2
|
-
--[[
|
|
3
|
-
Characterizes how the save-slot system handles the overflow-save failure: when a slot accumulates
|
|
4
|
-
more data than Roblox can serialize under its per-key size ceiling, the save must fail loudly
|
|
5
|
-
instead of silently dropping data or corrupting the slot that was already stored. Driven through the
|
|
6
|
-
same mock-injected PlayerDataStoreService and SaveSlotConstants substore layout the load flow uses
|
|
7
|
-
(see SaveSlotLoadFlow.spec), with the DataStoreMock configured to a small
|
|
8
|
-
[DataStoreMock.SetMaxValueLength] so the overflow triggers without a multi-megabyte payload.
|
|
9
|
-
|
|
10
|
-
@class SaveSlotOverflow.spec.lua
|
|
11
|
-
]]
|
|
12
|
-
local require = require(script.Parent.loader).load(script)
|
|
13
|
-
|
|
14
|
-
local DataStoreMock = require("DataStoreMock")
|
|
15
|
-
local DataStoreTestUtils = require("DataStoreTestUtils")
|
|
16
|
-
local Jest = require("Jest")
|
|
17
|
-
local Maid = require("Maid")
|
|
18
|
-
local PromiseTestUtils = require("PromiseTestUtils")
|
|
19
|
-
local SaveSlotConstants = require("SaveSlotConstants")
|
|
20
|
-
local ServiceBag = require("ServiceBag")
|
|
21
|
-
|
|
22
|
-
local describe = Jest.Globals.describe
|
|
23
|
-
local expect = Jest.Globals.expect
|
|
24
|
-
local it = Jest.Globals.it
|
|
25
|
-
|
|
26
|
-
local function setup(mock)
|
|
27
|
-
local maid = Maid.new()
|
|
28
|
-
mock = mock or DataStoreMock.new()
|
|
29
|
-
|
|
30
|
-
local serviceBag = maid:Add(ServiceBag.new())
|
|
31
|
-
local playerDataStoreService = serviceBag:GetService(require("PlayerDataStoreService"))
|
|
32
|
-
serviceBag:Init()
|
|
33
|
-
playerDataStoreService:SetRobloxDataStore(mock)
|
|
34
|
-
serviceBag:Start()
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
playerDataStoreService = playerDataStoreService,
|
|
38
|
-
mock = mock,
|
|
39
|
-
destroy = function()
|
|
40
|
-
-- The store the spec loaded is only destroyed by a removal, and a PlayerMock never fires the
|
|
41
|
-
-- real Players.PlayerRemoving, so shut down the way Roblox does or its auto-save loop outlives
|
|
42
|
-
-- this spec and fires inside a later package's window.
|
|
43
|
-
DataStoreTestUtils.awaitServiceShutdown(playerDataStoreService)
|
|
44
|
-
maid:DoCleaning()
|
|
45
|
-
end,
|
|
46
|
-
}
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
local function resolveDataStore(playerDataStoreService, userId)
|
|
50
|
-
local promise = playerDataStoreService:PromiseDataStore(userId)
|
|
51
|
-
if not PromiseTestUtils.awaitSettled(promise, 10) then
|
|
52
|
-
return nil
|
|
53
|
-
end
|
|
54
|
-
local ok, dataStore = promise:Yield()
|
|
55
|
-
if not ok then
|
|
56
|
-
return nil
|
|
57
|
-
end
|
|
58
|
-
return dataStore
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
local function getSlotStore(dataStore, slotId)
|
|
62
|
-
return dataStore
|
|
63
|
-
:GetSubStore(SaveSlotConstants.SYSTEM_STORE_KEY)
|
|
64
|
-
:GetSubStore(SaveSlotConstants.SLOT_STORE_KEY)
|
|
65
|
-
:GetSubStore(slotId)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
describe("save slot overflow save", function()
|
|
69
|
-
it("fails the save when a slot grows past the datastore size limit", function()
|
|
70
|
-
local controller = setup()
|
|
71
|
-
|
|
72
|
-
local dataStore = resolveDataStore(controller.playerDataStoreService, 1)
|
|
73
|
-
expect(dataStore).never.toBeNil()
|
|
74
|
-
|
|
75
|
-
local slotStore = getSlotStore(dataStore, "slot-abc")
|
|
76
|
-
|
|
77
|
-
slotStore:Store("coins", 25)
|
|
78
|
-
local firstSave = dataStore:Save()
|
|
79
|
-
expect(PromiseTestUtils.awaitSettled(firstSave, 10)).toEqual(true)
|
|
80
|
-
expect((firstSave:Yield())).toEqual(true)
|
|
81
|
-
|
|
82
|
-
controller.mock:SetMaxValueLength(8192)
|
|
83
|
-
slotStore:Store("blob", string.rep("A", 32768))
|
|
84
|
-
|
|
85
|
-
local savePromise = dataStore:Save()
|
|
86
|
-
expect(PromiseTestUtils.awaitSettled(savePromise, 10)).toEqual(true)
|
|
87
|
-
expect((savePromise:Yield())).toEqual(false)
|
|
88
|
-
|
|
89
|
-
-- Lift the limit before teardown so the session lock's final unlock-save can flush and release
|
|
90
|
-
-- cleanly, rather than throwing during cleanup and leaking a retry into a later spec (these all
|
|
91
|
-
-- share one test place).
|
|
92
|
-
controller.mock:SetMaxValueLength(nil)
|
|
93
|
-
controller:destroy()
|
|
94
|
-
end)
|
|
95
|
-
|
|
96
|
-
it("preserves the already-saved slot data when an oversized save fails", function()
|
|
97
|
-
local controller = setup()
|
|
98
|
-
|
|
99
|
-
local dataStore = resolveDataStore(controller.playerDataStoreService, 1)
|
|
100
|
-
expect(dataStore).never.toBeNil()
|
|
101
|
-
|
|
102
|
-
local slotStore = getSlotStore(dataStore, "slot-abc")
|
|
103
|
-
|
|
104
|
-
slotStore:Store("coins", 25)
|
|
105
|
-
local firstSave = dataStore:Save()
|
|
106
|
-
expect(PromiseTestUtils.awaitSettled(firstSave, 10)).toEqual(true)
|
|
107
|
-
expect((firstSave:Yield())).toEqual(true)
|
|
108
|
-
|
|
109
|
-
controller.mock:SetMaxValueLength(8192)
|
|
110
|
-
slotStore:Store("blob", string.rep("A", 32768))
|
|
111
|
-
|
|
112
|
-
local savePromise = dataStore:Save()
|
|
113
|
-
expect(PromiseTestUtils.awaitSettled(savePromise, 10)).toEqual(true)
|
|
114
|
-
expect((savePromise:Yield())).toEqual(false)
|
|
115
|
-
|
|
116
|
-
controller.mock:SetMaxValueLength(nil)
|
|
117
|
-
local loadPromise = slotStore:Load("coins")
|
|
118
|
-
expect(PromiseTestUtils.awaitSettled(loadPromise, 10)).toEqual(true)
|
|
119
|
-
local ok, value = loadPromise:Yield()
|
|
120
|
-
expect(ok).toEqual(true)
|
|
121
|
-
expect(value).toEqual(25)
|
|
122
|
-
|
|
123
|
-
controller:destroy()
|
|
124
|
-
end)
|
|
125
|
-
end)
|