| 876 | } |
| 877 | |
| 878 | func TestConcurrentUpdateSelect(t *testing.T) { |
| 879 | t.Parallel() |
| 880 | |
| 881 | db, err := Open(filepath.Join(t.TempDir(), "db")) |
| 882 | if err != nil { |
| 883 | t.Fatal(err) |
| 884 | } |
| 885 | t.Cleanup(func() { |
| 886 | if err := db.Close(); err != nil { |
| 887 | t.Fatal(err) |
| 888 | } |
| 889 | }) |
| 890 | |
| 891 | const folderID = "test" |
| 892 | |
| 893 | // Some local files |
| 894 | files := []protocol.FileInfo{ |
| 895 | genFile("test1", 1, 1), |
| 896 | genFile("test2", 2, 2), |
| 897 | genFile("test3", 3, 3), |
| 898 | genFile("test4", 4, 4), |
| 899 | } |
| 900 | |
| 901 | // Insert the files for a remote device |
| 902 | if err := db.Update(folderID, protocol.DeviceID{42}, files); err != nil { |
| 903 | t.Fatal() |
| 904 | } |
| 905 | |
| 906 | // Iterate over handled files and insert them for the local device. |
| 907 | // This is similar to a pattern we have in other places and should |
| 908 | // work. |
| 909 | handled := 0 |
| 910 | it, errFn := db.AllNeededGlobalFiles(folderID, protocol.LocalDeviceID, config.PullOrderAlphabetic, 0, 0) |
| 911 | for glob := range it { |
| 912 | glob.Version = glob.Version.Update(1) |
| 913 | if err := db.Update(folderID, protocol.LocalDeviceID, []protocol.FileInfo{glob}); err != nil { |
| 914 | t.Fatal(err) |
| 915 | } |
| 916 | handled++ |
| 917 | } |
| 918 | if err := errFn(); err != nil { |
| 919 | t.Fatal(err) |
| 920 | } |
| 921 | |
| 922 | if handled != len(files) { |
| 923 | t.Log(handled) |
| 924 | t.Error("should have handled all the files") |
| 925 | } |
| 926 | } |
| 927 | |
| 928 | func TestAllForBlocksHash(t *testing.T) { |
| 929 | t.Parallel() |