Skip to content
This repository has been archived by the owner on Jan 27, 2020. It is now read-only.

Make aggregateChanges more testable. #91

Merged
merged 8 commits into from
Jan 31, 2016
Merged

Conversation

plouj
Copy link

@plouj plouj commented Jan 30, 2016

Currently the last test (checkAggregation(3, []string{"a/deleted1", "a/deleted2", "a/deleted3", "a/deleted4", "b/deleted1", "b/deleted2"}, []string{"a", "b/deleted1", "b/deleted2"})
) fails. Unless I'm missing something I think that the deletes should have been aggregated into the parent dir (a in this case), but they aren't. Note that althought TestDeletesAggregation passes, in that case sub contains all 50 files, which I don't think is the intended result. Please correct me if I'm wrong.
I guess it's intentional that we notify syncthing about every deleted path.

Also, suggestions for more tests are welcome!

This makes the code slightly easier to follow and test. Plus having
less arguments is usually better too.

Note that the only caller (accumulateChanges) already checks that
paths is not empty.
…ment

By calling os.Stat aggregateChanges, which is otherwise a pure
function, interacts with its environment. Pulling it out into an
argument allows us to control the environment much easier by simply
mocking it in the unittests.
For example, previously, TestSTEvents would output:

syncwatcher_test.go:384: Invalid result for directory change: test1
syncwatcher_test.go:398: Callback not correctly triggered

Now it shows:

syncwatcher_test.go:384: Invalid result for directory change: (test1) []string{"file1", "file2"}
syncwatcher_test.go:398: Callback not correctly triggered
@Zillode
Copy link

Zillode commented Jan 31, 2016

Nice, again a great improvement.

I guess it's intentional that we notify syncthing about every deleted path.

I think this was related to how Syncthing handles the sub scan of deleted items. When we ask it to scan a deleted item it simply ignores the request, so we always need to inform the top dir. Not sure if this is still the case and whether it would work for nested folders.

Also, suggestions for more tests are welcome!

An integration test with Syncthing would be nice. So launching two sts and st-inotifies, creating a few files, deletes a few dirs and checking if the results match. (It doesn't need to be written in Go per se)
Note that st still has a few open issues in complex scenarios (syncthing/syncthing#2113).

Zillode added a commit that referenced this pull request Jan 31, 2016
Make aggregateChanges more testable.
@Zillode Zillode merged commit 28a5434 into syncthing:master Jan 31, 2016
@syncthing syncthing locked and limited conversation to collaborators Nov 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants