// Tests the processor in conjunction with the vcs. func TestGoldProcessor(t *testing.T) { // Set up mock VCS and run a servcer with the given data directory. vcs := ingestion.MockVCS(TEST_COMMITS) server, serverAddr := ingestion.StartTraceDBTestServer(t, TRACE_DB_FILENAME) defer server.Stop() defer testutils.Remove(t, TRACE_DB_FILENAME) ingesterConf := &sharedconfig.IngesterConfig{ ExtraParams: map[string]string{ CONFIG_TRACESERVICE: serverAddr, }, } // Set up the processor. processor, err := newGoldProcessor(vcs, ingesterConf, nil) assert.Nil(t, err) // Load the example file and process it. fsResult, err := ingestion.FileSystemResult(TEST_INGESTION_FILE, "./") assert.Nil(t, err) err = processor.Process(fsResult) assert.Nil(t, err) // Steal the traceDB used by the processor to verify the results. traceDB := processor.(*goldProcessor).traceDB startTime := time.Now().Add(-time.Hour * 24 * 10) commitIDs, err := traceDB.List(startTime, time.Now()) assert.Nil(t, err) assert.Equal(t, 1, len(FilterCommitIDs(commitIDs, "master"))) assert.Equal(t, 0, len(FilterCommitIDs(commitIDs, TEST_CODE_REVIEW_URL))) assert.Equal(t, 1, len(commitIDs)) assert.Equal(t, &tracedb.CommitID{ Timestamp: TEST_COMMITS[0].Timestamp.Unix(), ID: TEST_COMMITS[0].Hash, Source: "master", }, commitIDs[0]) // Get a tile and make sure we have the right number of traces. tile, _, err := traceDB.TileFromCommits(commitIDs) assert.Nil(t, err) traces := tile.Traces assert.Equal(t, len(TEST_ENTRIES), len(traces)) for _, testEntry := range TEST_ENTRIES { found, ok := traces[testEntry.key] assert.True(t, ok) goldTrace, ok := found.(*types.GoldenTrace) assert.True(t, ok) assert.Equal(t, 1, len(goldTrace.Values)) assert.Equal(t, testEntry.value, goldTrace.Values[0]) } assert.Equal(t, "master", commitIDs[0].Source) assert.Nil(t, traceDB.Close()) }
func TestTrybotPerfIngestion(t *testing.T) { b, err := ioutil.ReadFile(filepath.Join("testdata", "rietveld_response.txt")) assert.NoError(t, err) m := mockhttpclient.NewURLMock() m.Mock("https://codereview.chromium.org/api/1467533002/1", b) server, serverAddr := ingestion.StartTraceDBTestServer(t, "./trybot_test_trace.db") defer server.Stop() defer testutils.Remove(t, "./trybot_test_trace.db") ingesterConf := &sharedconfig.IngesterConfig{ ExtraParams: map[string]string{ CONFIG_TRACESERVICE: serverAddr, }, } processor, err := newPerfTrybotProcessor(nil, ingesterConf, nil) assert.Nil(t, err) processor.(*perfTrybotProcessor).review = rietveld.New("https://codereview.chromium.org", m.Client()) fsResult, err := ingestion.FileSystemResult(filepath.Join(TEST_DATA_DIR, "trybot.json"), TEST_DATA_DIR) assert.Nil(t, err) err = processor.Process(fsResult) assert.Nil(t, err) assert.Equal(t, 1, len(processor.(*perfTrybotProcessor).cache)) // Steal the traceDB used by the processor to verify the results. traceDB := processor.(*perfTrybotProcessor).traceDB startTime := time.Time{} commitIDs, err := traceDB.List(startTime, time.Now()) assert.Nil(t, err) assert.Equal(t, 1, len(commitIDs)) assert.Equal(t, &tracedb.CommitID{ Timestamp: 1448036640, ID: "1", Source: "https://codereview.chromium.org/1467533002", }, commitIDs[0]) // Get a tile and make sure we have the right number of traces. tile, _, err := traceDB.TileFromCommits(commitIDs) assert.Nil(t, err) traces := tile.Traces assert.Equal(t, 2, len(traces)) assert.Nil(t, traceDB.Close()) }
// Tests the processor in conjunction with the vcs. func TestTrybotGoldProcessor(t *testing.T) { // Set up mock VCS and run a servcer with the given data directory. vcs := ingestion.MockVCS(TEST_COMMITS) server, serverAddr := ingestion.StartTraceDBTestServer(t, TRYBOT_TRACE_DB_FILE) defer server.Stop() defer testutils.Remove(t, TRYBOT_TRACE_DB_FILE) ingesterConf := &sharedconfig.IngesterConfig{ ExtraParams: map[string]string{ CONFIG_TRACESERVICE: serverAddr, CONFIG_CODE_REVIEW_URL: TEST_CODE_REVIEW_URL, }, } // Set up the processor. processor, err := newGoldTrybotProcessor(vcs, ingesterConf) assert.Nil(t, err) // Load the example file and process it. fsResult, err := ingestion.FileSystemResult(TRYBOT_INGESTION_FILE) assert.Nil(t, err) err = processor.Process(fsResult) assert.Nil(t, err) // Steal the traceDB used by the processor to verify the results. traceDB := processor.(*goldTrybotProcessor).traceDB // The timestamp for the issue/patchset in the testfile is 1443718869. startTime := time.Unix(1443718868, 0) commitIDs, err := traceDB.List(startTime, time.Now()) assert.Nil(t, err) assert.Equal(t, 1, len(FilterCommitIDs(commitIDs, TRYBOT_SRC))) assert.Equal(t, 0, len(FilterCommitIDs(commitIDs, VCS_SRC))) assert.Equal(t, 1, len(commitIDs)) assert.Equal(t, &tracedb.CommitID{ Timestamp: time.Unix(1443718869, 0), ID: "1", Source: string(TRYBOT_SRC) + TEST_CODE_REVIEW_URL + "/1381483003", }, commitIDs[0]) // Get a tile and make sure we have the right number of traces. tile, err := traceDB.TileFromCommits(commitIDs) assert.Nil(t, err) traces := tile.Traces assert.Equal(t, len(TEST_ENTRIES), len(traces)) for _, testEntry := range TEST_ENTRIES { found, ok := traces[testEntry.key] assert.True(t, ok) goldTrace, ok := found.(*types.GoldenTrace) assert.True(t, ok) assert.Equal(t, 1, len(goldTrace.Values)) assert.Equal(t, testEntry.value, goldTrace.Values[0]) } // Make sure the prefix is stripped correctly. StripSourcePrefix(commitIDs) assert.Equal(t, TEST_CODE_REVIEW_URL+"/1381483003", commitIDs[0].Source) assert.Nil(t, traceDB.Close()) }