Skip to main content
  1. Posts/

Day 60 - News Stock

OldDays seitan-spin cucumber

In which we get just a few more tests written.

News of the day
#

Supporting the NEWS setting was pretty straightforward, even the multi-line stuff once I realized that having carriage returns in Ruby regular expressions doesn’t work well along with ^ and $ for some reason.

(Un)Stocking the Shelves
#

The next two settings to tackle are ClearStores and RestockStores, which clearly have to do with vendors, but what do they really do?

DragonsSpine/DragonsSpineMain.cs
201
202
203
204
205
206
207
#region Clear Stores / Restock stores
if (ConfigurationManager.AppSettings["ClearStores"].ToLower() == "true") // clear all store items that are not original store items
    StoreItem.ClearStores();

if (ConfigurationManager.AppSettings["RestockStores"].ToLower() == "true") // restock store merchants
    StoreItem.RestockStores();
#endregion

Makes sense, but how are “original” items, to be restocked, identified? A couple of stored procedures, apparently:

EntireDB-minimal.sql
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
----------------------------------------------------------------------------
-- Clear all items from Stores that are not Original
----------------------------------------------------------------------------
CREATE PROC [dbo].[prApp_Stores_Clear]

AS

DELETE	Stores
WHERE 	(original = 0)
GO
EntireDB-minimal.sql
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
----------------------------------------------------------------------------
-- Restock items in the Stores table
----------------------------------------------------------------------------
CREATE PROC [dbo].[prApp_Stores_Restock]

AS

UPDATE    Stores
SET              stocked = restock
WHERE     (original = 1) AND stocked <> restock
GO

So let’s first try a couple to tests that just give something to be cleared and to be restocked, then check the logs that it was supposedly done:

features/config_file.feature
167
168
169
170
171
172
173
174
175
176
177
178
Scenario: ClearStores True, RestockStores True causes stores to be reset on server startup
  Given I use the "minimal" database
  And I add a vendor "TestVend01"
  And I give vendor "TestVend01" the following items:
      | itemID  | notes      | original | stocked | restock |
      | 30480   | Small Rock | false    | 1       | 0       |
      | 33020   | Red Berries| true     | 7       | 33      |
  And I set "ClearStores" in the config file to "True"
    And I set "RestockStores" in the config file to "True"
  When the server executable is started
  And I allow time for the server to complete startup
  Then the log shows "1" items cleared from stores

…required a surprising amount of code to actually implement. A store needs to be attached to a merchant NPC, so we added some database code for both adding an NPC as well as adding items to a store. Watching the database confirms that the non-original “Small Rock” disappears, and the log reflects that. Then:

features/config_file.feature
183
184
185
186
187
188
189
190
191
192
193
194
Scenario: ClearStores True, RestockStores True causes stores to be restocked on server startup
  Given I use the "minimal" database
  And I add a vendor "TestVend01"
  And I give vendor "TestVend01" the following items:
      | itemID  | notes      | original | stocked | restock |
      | 30480   | Small Rock | false    | 1       | 0       |
      | 33020   | Red Berries| true     | 7       | 33      |
  And I set "ClearStores" in the config file to "True"
    And I set "RestockStores" in the config file to "True"
  When the server executable is started
  And I allow time for the server to complete startup
  And the log shows "1" items restocked in stores

So we watch the database and see the “Red Berries” get restocked back to 33. But the test still fails:

Waiting for log to contain "Restocked 1 store records.".
Waiting for log to contain "Restocked 1 store records.".
Waiting for log to contain "Restocked 1 store records.".
Waiting for log to contain "Restocked 1 store records.".
Waiting for log to contain "Restocked 1 store records.".
Waiting for log to contain "Restocked 1 store records.".
Waiting for log to contain "Restocked 1 store records.".
Waiting for log to contain "Restocked 1 store records.".
Waiting for log to contain "Restocked 1 store records.".
Waiting for log to contain "Restocked 1 store records.".
execution expired (Timeout::Error)
./features/lib/server_helper.rb:26:in `sleep'
./features/lib/server_helper.rb:26:in `block (2 levels) in log_contains'
./features/lib/server_helper.rb:20:in `loop'
./features/lib/server_helper.rb:20:in `block in log_contains'
./features/lib/server_helper.rb:19:in `log_contains'
./features/steps/vendor_steps.rb:27:in `/^the log shows "([^"]*)" items restocked in stores$/'

and in the log:

6/28/2016 9:52:25 PM: {SystemGo} Spawning NPCs.
6/28/2016 9:52:25 PM: {SystemGo} Deleted 1 store records.
6/28/2016 9:52:25 PM: {SystemGo} Restocked 0 store records.
6/28/2016 9:52:25 PM: {SystemGo} Master round timer started.

So the store is being restocked, but the log isn’t showing it. Drilling down through the DAL, we find that the stored procedure is returning 0 despite having actually changed rows. @bug and move on, hopefully it’ll be a simple fix.

Now how much will it take to have an actual in-world NPC merchant show its stores having been cleared and/or restocked? I’m eager to find out. Tomorrow.


Useful Stuff
#


More to come
More to come

Day 60 code - tests