Skip to content

Commit 8f0ea09

Browse files
author
Dan Brakeley
committed
remove longtest comparison of local files
* local files don't have to match what is in perforce (ie line endings) * upcoming performance improvements will change the behavior to where the local destination workspace folder won't be populated with unchanged depot files * also cleaned up the longtest shell scripts a bit
1 parent e13a7b0 commit 8f0ea09

5 files changed

Lines changed: 55 additions & 157 deletions

File tree

magefile.go

Lines changed: 7 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ package main
44

55
import (
66
"bytes"
7-
"crypto/md5"
8-
"encoding/hex"
9-
"fmt"
10-
"io"
11-
"io/fs"
12-
"os"
13-
"path/filepath"
14-
"sort"
157
"strings"
168
"time"
179

@@ -72,14 +64,12 @@ func LongTest() {
7264
sh.Cmdf("./%s -config ../test/config.toml", target).Run()
7365
})
7466
sh.InDir("test", func() {
75-
sh.Echo("Submitting CL and verifying depot files in both servers match...")
67+
sh.Echo("Submitting p4harmonize's CL...")
68+
sh.Cmdf("./submit.sh").Bash()
69+
sh.Echo("Verifying depot files in both servers match...")
7670
sh.Cmdf("./verify.sh").Bash()
7771
})
7872

79-
// The depot paths and types match, now let's check the file sizes and contents:
80-
sh.Echo("Comparing actual files (not just what perforce reports)...")
81-
sh.Must(compareFolderContents("./local/p4/src", "./local/p4/dst"))
82-
sh.Echo("All file sizes and contents match")
8373
sh.Echo("***")
8474
sh.Echo("*** Integration Test Passed!")
8575
sh.Echo("***")
@@ -92,9 +82,10 @@ func TestPrep() {
9282
sh.InDir("test", func() {
9383
sh.Echo("Running test/prep.sh...")
9484

95-
// TODO: FIXME: this sleep is to avoid running prep.sh before the perforce servers are ready
96-
// Ideally we'd have a test that actually confirms that the perforce servers are ready, rather
97-
// then just making a race condition less likely.
85+
// TODO: FIXME: This sleep is to reduce the chance of a race condition where prep.sh runs before
86+
// the perforce servers are actually accepting connections. I've only seen this issue on linux
87+
// (which was running in Windows via VMWare), and it was inconcsistent.
88+
// Ideally there would be some check we could make here instead of just waiting and hoping.
9889
time.Sleep(time.Second)
9990

10091
sh.Cmdf("./prep.sh").Bash()
@@ -119,97 +110,3 @@ func TestDown() {
119110
sh.Cmdf("docker compose rm -f").Run()
120111
})
121112
}
122-
123-
// helpers
124-
125-
type File struct {
126-
Name string
127-
Size int64
128-
Hash string
129-
}
130-
131-
func (l File) IsSameAs(r File) bool {
132-
return strings.ToLower(l.Name) == strings.ToLower(r.Name) && l.Size == r.Size && l.Hash == r.Hash
133-
}
134-
135-
type byNameLC []File
136-
137-
func (x byNameLC) Len() int { return len(x) }
138-
func (x byNameLC) Less(i, j int) bool { return strings.ToLower(x[i].Name) < strings.ToLower(x[j].Name) }
139-
func (x byNameLC) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
140-
141-
func compareFolderContents(src, dst string) error {
142-
srcFiles, err := getFolderContentsSorted(src)
143-
if err != nil {
144-
return err
145-
}
146-
dstFiles, err := getFolderContentsSorted(dst)
147-
if err != nil {
148-
return err
149-
}
150-
151-
ok := len(srcFiles) == len(dstFiles)
152-
if ok {
153-
for i := range srcFiles {
154-
if !srcFiles[i].IsSameAs(dstFiles[i]) {
155-
ok = false
156-
break
157-
}
158-
}
159-
}
160-
161-
if !ok {
162-
sh.Warnf("Mismatch between src (%d) and dst (%d):", len(srcFiles), len(dstFiles))
163-
sh.Warn("SOURCE:")
164-
for _, v := range srcFiles {
165-
sh.Warnf(" %v", v)
166-
}
167-
sh.Warn("DESTINATION:")
168-
for _, v := range dstFiles {
169-
sh.Warnf(" %v", v)
170-
}
171-
return fmt.Errorf("Test Failed")
172-
}
173-
return nil
174-
}
175-
176-
func getFolderContentsSorted(root string) ([]File, error) {
177-
cleanRoot := filepath.Clean(root)
178-
var out []File
179-
err := filepath.Walk(cleanRoot, func(path string, info fs.FileInfo, err error) error {
180-
if err != nil {
181-
return err
182-
}
183-
if info.IsDir() {
184-
return nil
185-
}
186-
hash, err := hashFile(path)
187-
if err != nil {
188-
return fmt.Errorf("error hashing '%s': %w", path, err)
189-
}
190-
out = append(out, File{
191-
Name: strings.TrimPrefix(path, cleanRoot),
192-
Size: info.Size(),
193-
Hash: hash,
194-
})
195-
return nil
196-
})
197-
if err != nil {
198-
return nil, err
199-
}
200-
sort.Sort(byNameLC(out))
201-
return out, err
202-
}
203-
204-
func hashFile(path string) (string, error) {
205-
file, err := os.Open(path)
206-
if err != nil {
207-
return "", err
208-
}
209-
defer file.Close()
210-
hash := md5.New()
211-
if _, err := io.Copy(hash, file); err != nil {
212-
return "", err
213-
}
214-
return hex.EncodeToString(hash.Sum(nil)), nil
215-
}

test/env.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
SRC_PORT=1667
4+
SRC_USER=super
5+
SRC_DEPOT=UE4
6+
SRC_STREAM=Release-4.20
7+
SRC_CLIENT=$SRC_USER-$SRC_DEPOT-$SRC_STREAM
8+
SRC_ROOT=../local/p4/src
9+
10+
if command -v cygpath > /dev/null; then
11+
## in cygwin-based bash (ie git bash) on windows
12+
SRC_ROOT_ABS=$(cygpath -a -w $SRC_ROOT | sed -e 's|\\|/|g')
13+
elif command -v realpath > /dev/null; then
14+
SRC_ROOT_ABS=$(realpath -m $SRC_ROOT)
15+
else
16+
echo "Unable to generate full path for $SRC_ROOT on this platform"
17+
exit 1
18+
fi
19+
20+
DST_PORT=1668
21+
DST_USER=super
22+
DST_DEPOT=test
23+
DST_STREAM=engine
24+
DST_CLIENT=$DST_USER-$DST_DEPOT-$DST_STREAM-p4harmonize
25+
DST_ROOT=../local/p4/dst
26+
27+
if command -v cygpath > /dev/null; then
28+
## in cygwin-based bash (ie git bash) on windows
29+
DST_ROOT_ABS=$(cygpath -a -w $DST_ROOT | sed -e 's|\\|/|g')
30+
elif command -v realpath > /dev/null; then
31+
DST_ROOT_ABS=$(realpath -m $DST_ROOT)
32+
else
33+
echo "Unable to generate full path for $DST_ROOT on this platform"
34+
exit 1
35+
fi

test/prep.sh

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,8 @@
11
#!/bin/bash
22
cd $(dirname "$0")
33

4-
SRC_PORT=1667
5-
SRC_USER=super
6-
SRC_DEPOT=UE4
7-
SRC_STREAM=Release-4.20
8-
SRC_CLIENT=$SRC_USER-$SRC_DEPOT-$SRC_STREAM
9-
SRC_ROOT=../local/p4/src
10-
11-
if command -v cygpath > /dev/null; then
12-
## in cygwin-based bash (ie git bash) on windows
13-
SRC_ROOT_ABS=$(cygpath -a -w $SRC_ROOT | sed -e 's|\\|/|g')
14-
elif command -v realpath > /dev/null; then
15-
SRC_ROOT_ABS=$(realpath -m $SRC_ROOT)
16-
else
17-
echo "Unable to generate full path for $SRC_ROOT on this platform"
18-
exit 1
19-
fi
20-
21-
DST_PORT=1668
22-
DST_USER=super
23-
DST_DEPOT=test
24-
DST_STREAM=engine
25-
DST_CLIENT=$DST_USER-$DST_DEPOT-$DST_STREAM
26-
DST_ROOT=../local/p4/dst
27-
28-
if command -v cygpath > /dev/null; then
29-
## in cygwin-based bash (ie git bash) on windows
30-
DST_ROOT_ABS=$(cygpath -a -w $DST_ROOT | sed -e 's|\\|/|g')
31-
elif command -v realpath > /dev/null; then
32-
DST_ROOT_ABS=$(realpath -m $DST_ROOT)
33-
else
34-
echo "Unable to generate full path for $DST_ROOT on this platform"
35-
exit 1
36-
fi
4+
source ./env.sh
5+
DST_CLIENT_ADD=$DST_USER-$DST_DEPOT-$DST_STREAM
376

387
SRC_P4="p4 -p $SRC_PORT -u $SRC_USER"
398
DST_P4="p4 -p $DST_PORT -u $DST_USER"
@@ -95,11 +64,11 @@ $DST_P4 --field "Type=mainline" stream -o //$DST_DEPOT/$DST_STREAM | $DST_P4 str
9564
$DST_P4 \
9665
--field "Root=$DST_ROOT_ABS" \
9766
--field "Stream=//$DST_DEPOT/$DST_STREAM" \
98-
--field "View=//$DST_DEPOT/$DST_STREAM/... //$DST_CLIENT/..." \
99-
client -o $DST_CLIENT | $DST_P4 client -i
67+
--field "View=//$DST_DEPOT/$DST_STREAM/... //$DST_CLIENT_ADD/..." \
68+
client -o $DST_CLIENT_ADD | $DST_P4 client -i
10069

10170

102-
DST_P4="$DST_P4 -c $DST_CLIENT"
71+
DST_P4="$DST_P4 -c $DST_CLIENT_ADD"
10372
CL=$($DST_P4 --field "Description=test" --field "Files=" change -o | $DST_P4 change -i | cut -d ' ' -f 2)
10473

10574
echo "Created CL $CL"

test/submit.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash -e
2+
cd $(dirname "$0")
3+
4+
source ./env.sh
5+
6+
# commit the change left open by p4harmonize
7+
p4 -p $DST_PORT -u $DST_USER -c $DST_CLIENT submit -c 3

test/verify.sh

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
#!/bin/bash -e
22
cd $(dirname "$0")
33

4-
SRC_PORT=1667
5-
SRC_USER=super
6-
SRC_CLIENT=super-UE4-Release-4.20
7-
8-
DST_PORT=1668
9-
DST_USER=super
10-
DST_CLIENT=super-test-engine-p4harmonize
4+
source ./env.sh
115

126
SRC_P4="p4 -p $SRC_PORT -u $SRC_USER -c $SRC_CLIENT"
137
DST_P4="p4 -p $DST_PORT -u $DST_USER -c $DST_CLIENT"
148

15-
# commit the change left open by p4harmonize
16-
17-
$DST_P4 submit -c 3
18-
199
# grab the list of files from each server and compare names and types
2010

2111
SRCFILES=`$SRC_P4 -z tag files -e //$SRC_CLIENT/... |\

0 commit comments

Comments
 (0)