filetype_test.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This program is free software: you can redistribute it and/or modify it
  4. // under the terms of the GNU General Public License as published by the Free
  5. // Software Foundation, either version 3 of the License, or (at your option)
  6. // any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful, but WITHOUT
  9. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. // more details.
  12. //
  13. // You should have received a copy of the GNU General Public License along
  14. // with this program. If not, see <http://www.gnu.org/licenses/>.
  15. // +build integration
  16. // This currently fails; it should be fixed
  17. package integration_test
  18. import (
  19. "log"
  20. "os"
  21. "strings"
  22. "testing"
  23. "time"
  24. )
  25. func TestFiletypeChange(t *testing.T) {
  26. log.Println("Cleaning...")
  27. err := removeAll("s1", "s2", "h1/index", "h2/index")
  28. if err != nil {
  29. t.Fatal(err)
  30. }
  31. log.Println("Generating files...")
  32. err = generateFiles("s1", 100, 20, "../bin/syncthing")
  33. if err != nil {
  34. t.Fatal(err)
  35. }
  36. // A file that we will replace with a directory later
  37. fd, err := os.Create("s1/fileToReplace")
  38. if err != nil {
  39. t.Fatal(err)
  40. }
  41. fd.Close()
  42. // A directory that we will replace with a file later
  43. err = os.Mkdir("s1/dirToReplace", 0755)
  44. if err != nil {
  45. t.Fatal(err)
  46. }
  47. // Verify that the files and directories sync to the other side
  48. log.Println("Syncing...")
  49. sender := syncthingProcess{ // id1
  50. log: "1.out",
  51. argv: []string{"-home", "h1"},
  52. port: 8081,
  53. apiKey: apiKey,
  54. }
  55. err = sender.start()
  56. if err != nil {
  57. t.Fatal(err)
  58. }
  59. receiver := syncthingProcess{ // id2
  60. log: "2.out",
  61. argv: []string{"-home", "h2"},
  62. port: 8082,
  63. apiKey: apiKey,
  64. }
  65. err = receiver.start()
  66. if err != nil {
  67. sender.stop()
  68. t.Fatal(err)
  69. }
  70. for {
  71. comp, err := sender.peerCompletion()
  72. if err != nil {
  73. if strings.Contains(err.Error(), "use of closed network connection") {
  74. time.Sleep(time.Second)
  75. continue
  76. }
  77. sender.stop()
  78. receiver.stop()
  79. t.Fatal(err)
  80. }
  81. curComp := comp[id2]
  82. if curComp == 100 {
  83. sender.stop()
  84. receiver.stop()
  85. break
  86. }
  87. time.Sleep(time.Second)
  88. }
  89. sender.stop()
  90. receiver.stop()
  91. log.Println("Comparing directories...")
  92. err = compareDirectories("s1", "s2")
  93. if err != nil {
  94. t.Fatal(err)
  95. }
  96. log.Println("Making some changes...")
  97. // Replace file with directory
  98. os.RemoveAll("s1/fileToReplace")
  99. err = os.Mkdir("s1/fileToReplace", 0755)
  100. if err != nil {
  101. t.Fatal(err)
  102. }
  103. // Replace directory with file
  104. os.RemoveAll("s1/dirToReplace")
  105. fd, err = os.Create("s1/dirToReplace")
  106. if err != nil {
  107. t.Fatal(err)
  108. }
  109. fd.Close()
  110. // Sync these changes and recheck
  111. log.Println("Syncing...")
  112. err = sender.start()
  113. if err != nil {
  114. t.Fatal(err)
  115. }
  116. err = receiver.start()
  117. if err != nil {
  118. sender.stop()
  119. t.Fatal(err)
  120. }
  121. for {
  122. comp, err := sender.peerCompletion()
  123. if err != nil {
  124. if strings.Contains(err.Error(), "use of closed network connection") {
  125. time.Sleep(time.Second)
  126. continue
  127. }
  128. sender.stop()
  129. receiver.stop()
  130. t.Fatal(err)
  131. }
  132. curComp := comp[id2]
  133. if curComp == 100 {
  134. sender.stop()
  135. receiver.stop()
  136. break
  137. }
  138. time.Sleep(time.Second)
  139. }
  140. sender.stop()
  141. receiver.stop()
  142. log.Println("Comparing directories...")
  143. err = compareDirectories("s1", "s2")
  144. if err != nil {
  145. t.Fatal(err)
  146. }
  147. }