0
我正在Firebase中運行兩個測試。一個版本通過,另一個版本不通過。如果在實際添加子項之前附加了child_removed回調,它將正常工作。插入後連接時不會觸發。child_removed並不總是在firebase上觸發
版本通過測試:該測試失敗
it("A) listens to child_removed raw (Before Insert)", function (done) {
this.timeout(5000);
let ref = DataServices.database.ref();
let pushRef = ref.child('test/testChildRemovedA').push();
let newKey = pushRef.key;
let insertPath = 'test/testChildRemovedA/' + newKey;
let callback = (snapshot) => { done(); }
DataServices.database.ref('test/testChildRemovedA/').on("child_removed", callback);
let updates = {};
updates[insertPath] = 'hi';
DataServices.database.ref().update(updates).then(() => {
updates[insertPath] = null;
DataServices.database.ref().update(updates);
});
});
版本:
it("B) listens to child_removed raw (After Insert)", function (done) {
this.timeout(10000);
let ref = DataServices.database.ref();
let pushRef = ref.child('test/testChildRemovedB').push();
let newKey = pushRef.key;
let insertPath = 'test/testChildRemovedB/' + newKey;
let callback = (snapshot) => { done(); }
let updates = {};
updates[insertPath] = 'hi';
DataServices.database.ref().update(updates).then(() => {
DataServices.database.ref('test/testChildRemovedB/').on("child_removed", callback);
updates[insertPath] = null;
DataServices.database.ref().update(updates);
});
});
唯一的區別是在child_removed事件附着,但在此之前的數據實際上是兩者都相連刪除。在這兩種情況下,數據都確實從Firebase中移除。
添加child_removed偵聽器時是否存在競爭條件?