def test_randomPrimed(self):
        print "Random hits/misses:"
        testsPerType = REQUEST_COUNT / 3

        print "Loading requests/responses"
        expectedResponses = {}
        requests = []

        # Memcached hits
        request = testUtils.sampleRequest()
        response = testUtils.sampleResponse()
        for i in xrange(testsPerType):
            requests.append(request)
        expectedResponses[request] = response
        memcachedPrimingRequest = request
        memcachedPrimingReponse = response

        # DiskCache hits
        with open(DISK_CACHE_HIT_REQUEST_PATH, 'r') as fp:
            requestData = json.load(fp)
        random.shuffle(requestData)
        primingData = requestData.pop(0)
        diskCachePrimingRequest = json.dumps(primingData['request'])
        diskCachePrimingResponse = json.dumps(primingData['response'])
        requestData = requestData[:testsPerType]

        for data in requestData:
            request = json.dumps(data['request'])
            response = json.dumps(data['response'])
            expectedResponses[request] = response
            requests.append(request)

        # Cache misses
        with open(CACHE_MISS_REQUEST_PATH, 'r') as fp:
            requestData = json.load(fp)
        random.shuffle(requestData)
        requestData = requestData[:testsPerType]

        for data in requestData:
            request = json.dumps(data['request'])
            response = json.dumps(data['response'])
            expectedResponses[request] = response
            requests.append(request)
        del requestData
        print "Done loading requests/responses"

        print "Priming cache"
        response = testUtils.symServerRequest(memcachedPrimingRequest,
                                              "127.0.0.1",
                                              self.config['SymServer']['port'])
        testUtils.verifyExpectedResponse(self, memcachedPrimingReponse,
                                         response)
        response = testUtils.symServerRequest(diskCachePrimingRequest,
                                              "127.0.0.1",
                                              self.config['SymServer']['port'])
        testUtils.verifyExpectedResponse(self, diskCachePrimingResponse,
                                         response)
        print "Done priming cache"

        self.makeRequestsCheckResponses(requests, expectedResponses)
    def test_diskCacheHitsPrimed(self):
        print "DiskCache hits:"
        print "Loading requests/responses..."
        with open(DISK_CACHE_HIT_REQUEST_PATH, 'r') as fp:
            requestData = json.load(fp)
        random.shuffle(requestData)
        primingData = requestData.pop(0)
        # Truncate the list to the desired length
        requestData = requestData[:REQUEST_COUNT]
        expectedResponses = {}
        requests = []

        for data in requestData:
            request = json.dumps(data['request'])
            response = json.dumps(data['response'])
            expectedResponses[request] = response
            requests.append(request)
        del requestData
        print "Done loading requests/responses"

        print "Priming cache..."
        request = json.dumps(primingData['request'])
        expectedResponse = json.dumps(primingData['response'])
        response = testUtils.symServerRequest(request, "127.0.0.1",
                                              self.config['SymServer']['port'])
        testUtils.verifyExpectedResponse(self, expectedResponse, response)
        print "Done priming cache."

        self.makeRequestsCheckResponses(requests, expectedResponses)
Пример #3
0
 def test_badRequest5(self):
     request = '{"stacks":[[[0,11723767],[1, 65802]]],'
     # Memory map missing altogether
     request += '"version":4}'
     response = testUtils.symServerRequest(
         request, ip="127.0.0.1", port=self.config['SymServer']['port'])
     self.assertEqual(response['code'], 400,
                      "HTTP Status code should be 400")
Пример #4
0
 def test_badRequest7(self):
     # No stacks
     request = '{'
     request += '"memoryMap":[["xul.pdb","44E4EC8C2F41492B9369D6B9A059577C2"],'
     request += '["wntdll.pdb","D74F79EB1F8D4A45ABCD2F476CCABACC2"]],'
     request += '"version":4}'
     response = testUtils.symServerRequest(
         request, ip="127.0.0.1", port=self.config['SymServer']['port'])
     self.assertEqual(response['code'], 400,
                      "HTTP Status code should be 400")
Пример #5
0
 def test_badRequest4(self):
     request = '{"stacks":[[[0,11723767],[1, 65802]]],'
     request += '"memoryMap":[["xul.pdb","44E4EC8C2F41492B9369D6B9A059577C2"],'
     # Memory map missing entries
     request += '],'
     request += '"version":4}'
     response = testUtils.symServerRequest(
         request, ip="127.0.0.1", port=self.config['SymServer']['port'])
     self.assertEqual(response['code'], 400,
                      "HTTP Status code should be 400")
 def test_verifyCachedSymbolFile(self):
     request = {
         "debug": True,
         "action": "cacheAddRaw",
         "libName": LIB_NAME,
         "breakpadId": BREAKPAD_ID
     }
     request = json.dumps(request)
     response = testUtils.symServerRequest(
         request, ip="127.0.0.1", port=self.config['DiskCache']['port'])
     response = testUtils.verifyGenericResponse(self, response)
     self.assertIn('path', response, "No path provided in response")
     downloadHash = testUtils.md5(response['path'])
     self.assertEqual(
         downloadHash.lower(), EXPECTED_HASH.lower(),
         "Cached symbol file hash does not match the expected hash")
    def test_memcachedHitsPrimed(self):
        print "Memcached hits:"
        request = testUtils.sampleRequest()

        requests = []
        expectedResponses = {request: testUtils.sampleResponse()}
        for index in xrange(REQUEST_COUNT):
            requests.append(request)

        print "Priming cache..."
        response = testUtils.symServerRequest(request, "127.0.0.1",
                                              self.config['SymServer']['port'])
        testUtils.verifySampleResponse(self, response)
        print "Done priming cache."

        self.makeRequestsCheckResponses(requests, expectedResponses)
Пример #8
0
 def test_badRequest2(self):
     request = "This is not JSON"
     response = testUtils.symServerRequest(
         request, ip="127.0.0.1", port=self.config['SymServer']['port'])
     self.assertEqual(response['code'], 400,
                      "HTTP Status code should be 400")
Пример #9
0
 def test_sampleRequest(self):
     request = testUtils.sampleRequest()
     response = testUtils.symServerRequest(
         request, ip="127.0.0.1", port=self.config['SymServer']['port'])
     testUtils.verifySampleResponse(self, response)
    def test_verifyCache(self):
        # The DiskCache was created with a brand new cache directory. There should
        # be nothing in the cache
        request = {
            "debug": True,
            "action": "cacheExists",
            "libName": LIB_NAME,
            "breakpadId": BREAKPAD_ID
        }
        JSONrequest = json.dumps(request)
        response = testUtils.symServerRequest(
            JSONrequest, ip="127.0.0.1", port=self.config['DiskCache']['port'])
        response = testUtils.verifyGenericResponse(self, response)
        self.assertIn('exists', response,
                      "No result provided in response to Exists")
        self.assertFalse(response['exists'],
                         "Value is still in cache after eviction")

        request['action'] = 'cacheAddRaw'
        JSONrequest = json.dumps(request)
        response = testUtils.symServerRequest(
            JSONrequest, ip="127.0.0.1", port=self.config['DiskCache']['port'])
        response = testUtils.verifyGenericResponse(self, response)
        self.assertIn('path', response, "No path provided in response to Add")
        downloadHash = testUtils.md5(response['path'])
        self.assertEqual(
            downloadHash.lower(), EXPECTED_HASH.lower(),
            "Added symbol file hash does not match the expected hash")

        request['action'] = 'cacheExists'
        JSONrequest = json.dumps(request)
        response = testUtils.symServerRequest(
            JSONrequest, ip="127.0.0.1", port=self.config['DiskCache']['port'])
        response = testUtils.verifyGenericResponse(self, response)
        self.assertIn('exists', response,
                      "No result provided in response to Exists")
        self.assertTrue(response['exists'], "Value not in cache after adding")

        request['action'] = 'cacheGet'
        JSONrequest = json.dumps(request)
        response = testUtils.symServerRequest(
            JSONrequest, ip="127.0.0.1", port=self.config['DiskCache']['port'])
        response = testUtils.verifyGenericResponse(self, response)
        self.assertIn('path', response, "No path provided in response to Get")
        cachePath = response['path']
        downloadHash = testUtils.md5(cachePath)
        self.assertEqual(
            downloadHash.lower(), EXPECTED_HASH.lower(),
            "Added symbol file hash does not match the expected hash")

        request['action'] = 'cacheEvict'
        JSONrequest = json.dumps(request)
        response = testUtils.symServerRequest(
            JSONrequest, ip="127.0.0.1", port=self.config['DiskCache']['port'])
        response = testUtils.verifyGenericResponse(self, response)
        self.assertIn('success', response,
                      "No result provided in response to Evict")
        self.assertTrue(response['success'], "Cache eviction unsuccessful.")
        self.assertFalse(os.path.exists(cachePath),
                         "Cache file should not exist after eviction")

        request['action'] = 'cacheExists'
        JSONrequest = json.dumps(request)
        response = testUtils.symServerRequest(
            JSONrequest, ip="127.0.0.1", port=self.config['DiskCache']['port'])
        response = testUtils.verifyGenericResponse(self, response)
        self.assertIn('exists', response,
                      "No result provided in response to Exists")
        self.assertFalse(response['exists'],
                         "Value is still in cache after eviction")

        request['action'] = 'cacheGet'
        JSONrequest = json.dumps(request)
        response = testUtils.symServerRequest(
            JSONrequest, ip="127.0.0.1", port=self.config['DiskCache']['port'])
        response = testUtils.verifyGenericResponse(self, response)
        self.assertIn('path', response, "No path provided in response to Get")
        # Don't test the md5 hash. We didn't get the raw symbol file.
        self.assertTrue(os.path.exists(response['path']),
                        "Cached file does not exist after a cacheGet")
    def test_cache(self):
        request = {
            "debug": True,
            "action": "outputCacheHits",
            "enabled": True
        }
        JSONrequest = json.dumps(request)
        response = testUtils.symServerRequest(JSONrequest, ip="127.0.0.1",
                                              port=self.config['SymServer']['port'])
        response = testUtils.verifyGenericResponse(self, response)
        self.assertIn('success', response, "No result provided in response")

        JSONrequest = testUtils.sampleRequest()
        response = testUtils.symServerRequest(JSONrequest, ip="127.0.0.1",
                                              port=self.config['SymServer']['port'])
        response = testUtils.verifySampleResponse(self, response)
        self.assertIn('cacheHits', response)
        for stackHits in response['cacheHits']:
            for frameHit in stackHits:
                self.assertFalse(frameHit, "Should not have gotten any cache hits "
                                 "right after the server is started")

        response = testUtils.symServerRequest(JSONrequest, ip="127.0.0.1",
                                              port=self.config['SymServer']['port'])
        response = testUtils.verifySampleResponse(self, response)
        self.assertIn('cacheHits', response)
        for stackHits in response['cacheHits']:
            for frameHit in stackHits:
                self.assertTrue(frameHit, "Should not have gotten any cache misses "
                                "on the second query")

        # Evict items from the cache
        request = json.loads(JSONrequest)
        memoryMap = request['memoryMap']
        for stack in request['stacks']:
            for frame in stack:
                moduleId, offset = frame
                libName, breakpadId = memoryMap[moduleId]
                evictRequest = {
                    "debug": True,
                    "action": "cacheEvict",
                    "libName": libName,
                    "breakpadId": breakpadId,
                    "offset": offset
                }
                evictRequest = json.dumps(evictRequest)
                response = testUtils.symServerRequest(evictRequest, ip="127.0.0.1",
                                                      port=self.config['SymServer']['port'])
                response = testUtils.verifyGenericResponse(self, response)
                self.assertIn('success', response,
                              "No result provided in eviction reponse")
                self.assertTrue(response['success'], "Eviction request unsuccessful")

        response = testUtils.symServerRequest(JSONrequest, ip="127.0.0.1",
                                              port=self.config['SymServer']['port'])
        response = testUtils.verifySampleResponse(self, response)
        self.assertIn('cacheHits', response)
        for stackHits in response['cacheHits']:
            for frameHit in stackHits:
                self.assertFalse(frameHit, "Should not have gotten any cache hits "
                                 "right after all cache items are evicted")

        response = testUtils.symServerRequest(JSONrequest, ip="127.0.0.1",
                                              port=self.config['SymServer']['port'])
        response = testUtils.verifySampleResponse(self, response)
        self.assertIn('cacheHits', response)
        for stackHits in response['cacheHits']:
            for frameHit in stackHits:
                self.assertTrue(frameHit, "Should not have gotten any cache misses "
                                "on the second query")
 def run(self):
     response = testUtils.symServerRequest(self.request, "127.0.0.1",
                                           self.port)
     self.responseQueue.put((self.request, response))