Skip to content

Commit 4612204

Browse files
committed
Add 'real-world' import-feed JS stack overflow test
1 parent 3a4b9c5 commit 4612204

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

rest/importtest/import_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,42 @@ func TestImportFeed(t *testing.T) {
7373
assert.Equal(t, int64(1), rt.GetDatabase().DbStats.SharedBucketImportStats.ImportCount.Value())
7474
}
7575

76+
func TestImportFeedWithRecursiveSyncFunction(t *testing.T) {
77+
78+
base.SkipImportTestsIfNotEnabled(t)
79+
80+
rtConfig := rest.RestTesterConfig{
81+
SyncFn: `function access(doc) { access("foo", "bar"); }`,
82+
AutoImport: base.Ptr(true),
83+
}
84+
85+
rt := rest.NewRestTester(t, &rtConfig)
86+
defer rt.Close()
87+
dataStore := rt.GetSingleDataStore()
88+
89+
base.SetUpTestLogging(t, base.LevelDebug, base.KeyImport, base.KeyCRUD)
90+
91+
// Create doc via the SDK
92+
mobileKey := t.Name()
93+
mobileBody := make(map[string]interface{})
94+
mobileBody["channels"] = "ABC"
95+
_, err := dataStore.Add(mobileKey, 0, mobileBody)
96+
assert.NoError(t, err, "Error writing SDK doc")
97+
98+
// Wait for import
99+
err = rt.WaitForCondition(func() bool {
100+
return rt.GetDatabase().DbStats.SharedBucketImportStats.ImportErrorCount.Value() == 1
101+
})
102+
require.NoError(t, err)
103+
104+
// Attempt to get the document via Sync Gateway.
105+
response := rt.SendAdminRequest("GET", "/{{.keyspace}}/"+mobileKey, "")
106+
assert.Equal(t, 404, response.Code)
107+
108+
// Verify this didn't trigger an on-demand import
109+
assert.Equal(t, int64(0), rt.GetDatabase().DbStats.SharedBucketImportStats.ImportCount.Value())
110+
}
111+
76112
// Test import of an SDK delete.
77113
func TestXattrImportOldDoc(t *testing.T) {
78114
rtConfig := rest.RestTesterConfig{

0 commit comments

Comments
 (0)