filetype_test.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. err = sender.stop()
  90. if err != nil {
  91. t.Fatal(err)
  92. }
  93. err = receiver.stop()
  94. if err != nil {
  95. t.Fatal(err)
  96. }
  97. log.Println("Comparing directories...")
  98. err = compareDirectories("s1", "s2")
  99. if err != nil {
  100. t.Fatal(err)
  101. }
  102. log.Println("Making some changes...")
  103. // Replace file with directory
  104. os.RemoveAll("s1/fileToReplace")
  105. err = os.Mkdir("s1/fileToReplace", 0755)
  106. if err != nil {
  107. t.Fatal(err)
  108. }
  109. // Replace directory with file
  110. os.RemoveAll("s1/dirToReplace")
  111. fd, err = os.Create("s1/dirToReplace")
  112. if err != nil {
  113. t.Fatal(err)
  114. }
  115. fd.Close()
  116. // Sync these changes and recheck
  117. log.Println("Syncing...")
  118. err = sender.start()
  119. if err != nil {
  120. t.Fatal(err)
  121. }
  122. err = receiver.start()
  123. if err != nil {
  124. _ = sender.stop()
  125. t.Fatal(err)
  126. }
  127. for {
  128. comp, err := sender.peerCompletion()
  129. if err != nil {
  130. if strings.Contains(err.Error(), "use of closed network connection") {
  131. time.Sleep(time.Second)
  132. continue
  133. }
  134. _ = sender.stop()
  135. _ = receiver.stop()
  136. t.Fatal(err)
  137. }
  138. curComp := comp[id2]
  139. if curComp == 100 {
  140. break
  141. }
  142. time.Sleep(time.Second)
  143. }
  144. err = sender.stop()
  145. if err != nil {
  146. t.Fatal(err)
  147. }
  148. err = receiver.stop()
  149. if err != nil {
  150. t.Fatal(err)
  151. }
  152. log.Println("Comparing directories...")
  153. err = compareDirectories("s1", "s2")
  154. if err != nil {
  155. t.Fatal(err)
  156. }
  157. }