Skip to content

Commit

Permalink
Add property based testing to improve the atom/linux watcher (#1271)
Browse files Browse the repository at this point in the history
  • Loading branch information
nono authored Nov 13, 2018
1 parent 91f92a6 commit 5cd78cc
Show file tree
Hide file tree
Showing 7 changed files with 702 additions and 14 deletions.
16 changes: 10 additions & 6 deletions core/local/layers/checksum.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ module.exports = class ChecksumLayer extends Sequential /*:: implements Layer */
}

async doProcess (events /*: LayerEvent[] */) {
const batch = []
for (const event of events) {
if (['add', 'update'].includes(event.action) && event.doc.docType === 'file') {
try {
try {
if (['add', 'update'].includes(event.action) && event.doc.docType === 'file') {
event.doc.md5sum = await this.checksumer.push(event.abspath)
} catch (err) {
// TODO
console.error(err)
}
batch.push(event)
} catch (err) {
// TODO Currently, we ignore events when there is an error for
// computing the checksum as it is often just because the file has been
// deleted since. But we should have a more fine-grained error handling
// here.
}
}
return events
return batch
}
}
8 changes: 6 additions & 2 deletions core/local/layers/linux.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ module.exports = class LinuxSource {

async watch (relativePath /*: string */) {
try {
if (!this.running || this.watchers.has(relativePath)) {
return
}
const fullPath = path.join(this.syncPath, relativePath)
const w = await watcher.watchPath(fullPath, {}, this.process)
if (!this.running) {
if (!this.running || this.watchers.has(relativePath)) {
w.dispose()
return
}
Expand Down Expand Up @@ -82,6 +85,7 @@ module.exports = class LinuxSource {
}

async process (events /*: AtomWatcherEvent[] */) {
// TODO preserve order of batches
// TODO logger
// TODO ignore
const batch /*: LayerEvent[] */ = []
Expand All @@ -91,7 +95,7 @@ module.exports = class LinuxSource {
const eAdd = await this.buildAddEvent(event.path)
batch.push(eAdd)
if (eAdd.doc.docType === 'folder') {
this.watch(eAdd.doc.path)
this.watch(eAdd.doc.path).catch(err => { console.error(err) })
}
break
case 'modified':
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"test:elm": "elm-test",
"test:integration": "yarn mocha test/integration",
"test:performance": "yarn mocha test/performance",
"test:property": "NO_ELECTRON=true mocha test/property",
"test:property": "NO_ELECTRON=true mocha --exit test/property",
"test:scenarios": "yarn mocha test/scenarios/run.js",
"test:setup": "yarn docker:exec /cozy-desktop/test/setup.sh",
"test:unit": "yarn mocha test/unit/",
Expand Down
6 changes: 3 additions & 3 deletions test/generate_property_json.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

const faker = require('faker')

const nbInitOps = 16
const nbRunOps = 64
const specialChars = [':', '_', 'é', ' ', '%', '\\', '&', '@', 'É', 'Ç']
const nbInitOps = 32
const nbRunOps = 128
const specialChars = [':', '-', 'é', ' ', '%', ',', '&', '@', 'É', 'Ç']

const knownPaths = []
const deletedPaths = []
Expand Down
213 changes: 213 additions & 0 deletions test/property/local_watcher/bedfordshire.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
[
{ "op": "mkdir", "path": "indexing.gim" },
{
"op": "create_file",
"path": "indexing.gim/payment_investor_channels.ddd",
"size": 21
},
{ "op": "mkdir", "path": "INDEXING.GIM" },
{ "op": "start" },
{ "op": "mkdir", "path": "INDEXING.GIM" },
{ "op": "mkdir", "path": "indexing.gim/buckinghamshire_tools_invoice.hjson" },
{
"op": "mkdir",
"path": "indexing.gim/buckinghamshire_tools_invoice.hjson/bedfordshire_shirt_chad.mdp"
},
{
"op": "mkdir",
"path": "indexing.gim/payment_investor_channels.ddd/scalable.c4g"
},
{
"op": "mv",
"from": "indexing.gim/buckinghamshire_tools_invoice.hjson",
"to": "indexing.gim/buckinghamshire_tools_invoice.hjson/bedfordshire_shirt_chad.mdp/css_empowering_borders.ltf"
},
{ "op": "rm", "path": "indexing.gim" },
{ "op": "create_file", "path": "indexing.gim" },
{
"op": "create_file",
"path": "indexing.gim/buckinghamshire_tools_invoice.hjson/planner_plastic.setpay",
"size": 4118
},
{ "op": "rm", "path": "indexing.gim/payment_investor_channels.ddd" },
{
"op": "mv",
"from": "indexing.gim/payment_investor_channels.ddd",
"to": "indexing.gim/payment_investor_channels.ddd"
},
{
"op": "rm",
"path": "indexing.gim/buckinghamshire_tools_invoice.hjson/planner_plastic.setpay"
},
{
"op": "create_file",
"path": "indexing.gim/buckinghamshire_tools_invoice.hjson"
},
{ "op": "rm", "path": "indexing.gim/buckinghamshire_tools_invoice.hjson" },
{
"op": "mv",
"from": "indexing.gim/buckinghamshire_tools_invoice.hjson/planner_plastic.setpay",
"to": "indexing.gim/payment_investor_channels.ddd"
},
{
"op": "mv",
"from": "indexing.gim/buckinghamshire_tools_invoice.hjson/bedfordshire_shirt_chad.mdp/css_empowering_borders.ltf",
"to": "indexing.gim/buckinghamshire_tools_invoice.hjson/planner_plastic.setpay/reboot_granite_delaware.hh"
},
{
"op": "rm",
"path": "indexing.gim/payment_investor_channels.ddd/scalable.c4g"
},
{
"op": "rm",
"path": "indexing.gim/buckinghamshire_tools_invoice.hjson/planner_plastic.setpay"
},
{
"op": "create_file",
"path": "indexing.gim/payment_investor_channels.ddd/scalable.c4g/tools_best_of_breed.iso",
"size": 1048587
},
{ "op": "create_file", "path": "hacking_didactic.prf", "size": 262161 },
{ "op": "mv", "from": "indexing.gim", "to": "garden_paradigms.m1v" },
{
"op": "mv",
"from": "indexing.gim/payment_investor_channels.ddd",
"to": "indexing.gim/buckinghamshire_tools_invoice.hjson/bedfordshire_shirt_chad.mdp/css_empowering_borders.ltf/Éavon_feed_buckinghamshire.uvvf"
},
{
"op": "create_file",
"path": "indexing.gim/buckinghamshire_tools_invoice.hjson/bedfordshire_shirt_chad.mdp/css_empowering_borders.ltf/actuating.uvvs",
"size": 16393
},
{
"op": "mv",
"from": "indexing.gim/buckinghamshire_tools_invoice.hjson/bedfordshire_shirt_chad.mdp/css_empowering_borders.ltf",
"to": "indexing.gim/buckinghamshire_tools_invoice.hjson/planner_plastic.setpay"
},
{
"op": "rm",
"path": "indexing.gim/buckinghamshire_tools_invoice.hjson/planner_plastic.setpay"
},
{
"op": "mv",
"from": "indexing.gim/payment_investor_channels.ddd/scalable.c4g/tools_best_of_breed.iso",
"to": "pixel_palestinian_territory.dbk"
},
{ "op": "rm", "path": "garden_paradigms.m1v" },
{ "op": "create_file", "path": "Ésecondary.uvv", "size": 16406 },
{ "op": "mkdir", "path": "garden_paradigms.m1v" },
{
"op": "mv",
"from": "indexing.gim/buckinghamshire_tools_invoice.hjson/planner_plastic.setpay/reboot_granite_delaware.hh",
"to": "indexing.gim/payment_investor_channels.ddd"
},
{
"op": "mv",
"from": "indexing.gim/buckinghamshire_tools_invoice.hjson/bedfordshire_shirt_chad.mdp",
"to": "indexing.gim/buckinghamshire_tools_invoice.hjson/planner_plastic.setpay"
},
{
"op": "mv",
"from": "indexing.gim/buckinghamshire_tools_invoice.hjson/bedfordshire_shirt_chad.mdp/css_empowering_borders.ltf",
"to": "indexing.gim/payment_investor_channels.ddd/scalable.c4g"
},
{ "op": "mkdir", "path": "indexing.gim/buckinghamshire_tools_invoice.hjson" },
{
"op": "update_file",
"path": "indexing.gim/payment_investor_channels.ddd/scalable.c4g/tools_best_of_breed.iso",
"size": 58
},
{ "op": "update_file", "path": "indexing.gim", "size": 260 },
{
"op": "create_file",
"path": "indexing.gim/buckinghamshire_tools_invoice.hjson/bedfordshire_shirt_chad.mdp/css_empowering_borders.ltf/generating.pot",
"size": 73
},
{
"op": "mv",
"from": "indexing.gim/buckinghamshire_tools_invoice.hjson",
"to": "indexing.gim/buckinghamshire_tools_invoice.hjson/bedfordshire_shirt_chad.mdp/css_empowering_borders.ltf"
},
{ "op": "rm", "path": "Ésecondary.uvv" },
{ "op": "mkdir", "path": "garden_paradigms.m1v/firewall_california.onetmp" },
{
"op": "create_file",
"path": "indexing.gim/payment_investor_channels.ddd/scalable.c4g"
},
{
"op": "update_file",
"path": "indexing.gim/payment_investor_channels.ddd/scalable.c4g",
"size": 262153
},
{
"op": "mkdir",
"path": "hacking_didactic.prf/west_virginia_sausages_customer.hpgl"
},
{
"op": "create_file",
"path": "hacking_didactic.prf/west_virginia_sausages_customer.hpgl/wireless_metal.sub",
"size": 32774
},
{
"op": "rm",
"path": "hacking_didactic.prf/west_virginia_sausages_customer.hpgl"
},
{
"op": "mv",
"from": "garden_paradigms.m1v/firewall_california.onetmp",
"to": "indexing.gim/payment_investor_channels.ddd/scalable.c4g/tools_best_of_breed.iso"
},
{
"op": "update_file",
"path": "indexing.gim/buckinghamshire_tools_invoice.hjson/bedfordshire_shirt_chad.mdp/css_empowering_borders.ltf/actuating.uvvs",
"size": 1048577
},
{ "op": "rm", "path": "Ésecondary.uvv" },
{ "op": "mkdir", "path": "Çadministrator_infrastructure.apr" },
{
"op": "mv",
"from": "indexing.gim/buckinghamshire_tools_invoice.hjson/bedfordshire_shirt_chad.mdp/css_empowering_borders.ltf/actuating.uvvs",
"to": "indexing.gim/buckinghamshire_tools_invoice.hjson/planner_plastic.setpay"
},
{
"op": "mkdir",
"path": "INDEXING.GIM/BUCKINGHAMSHIRE_TOOLS_INVOICE.HJSON/BEDFORDSHIRE_SHIRT_CHAD.MDP/CSS_EMPOWERING_BORDERS.LTF"
},
{
"op": "update_file",
"path": "indexing.gim/buckinghamshire_tools_invoice.hjson",
"size": 32778
},
{ "op": "rm", "path": "garden_paradigms.m1v" },
{
"op": "mkdir",
"path": "garden_paradigms.m1v/firewall_california.onetmp/primary_xss.wri"
},
{
"op": "create_file",
"path": "indexing.gim/buckinghamshire_tools_invoice.hjson/bedfordshire_shirt_chad.mdp/css_empowering_borders.ltf/generating.pot/sensor_metrics.c4u",
"size": 28
},
{
"op": "mv",
"from": "indexing.gim",
"to": "hacking_didactic.prf/oregon_idaho_games.coffee"
},
{
"op": "mv",
"from": "indexing.gim/buckinghamshire_tools_invoice.hjson/bedfordshire_shirt_chad.mdp/css_empowering_borders.ltf/generating.pot",
"to": "Ésecondary.uvv"
},
{ "op": "create_file", "path": "games_granite_fuchsia.t", "size": 18 },
{
"op": "mv",
"from": "Ésecondary.uvv",
"to": "indexing.gim/buckinghamshire_tools_invoice.hjson/bedfordshire_shirt_chad.mdp/css_empowering_borders.ltf/actuating.uvvs"
},
{
"op": "create_file",
"path": "violet_movies_money_market_account.bmp",
"size": 524310
},
{ "op": "rm", "path": "indexing.gim/payment_investor_channels.ddd" }
]
Loading

0 comments on commit 5cd78cc

Please sign in to comment.