Esempio n. 1
0
    def test_cells_garbage_collection(self):
        # create a cell that subscribes to a specific 'thing', but that
        # creates new cells each time, and verify that we reduce our
        # cell count, and that we send deletion messages

        # subscribes to the set of cells with k=0 and displays something
        self.cells.withRoot(
            SubscribedSequence(
                lambda: Thing.lookupAll(k=0),
                lambda thing: Subscribed(lambda: Span("Thing(k=%s).x = %s" %
                                                      (thing.k, thing.x)))))

        with self.db.transaction():
            thing = Thing(x=1, k=0)

        for i in range(100):
            with self.db.transaction():
                thing.k = 1
                thing = Thing(x=i, k=0)

                for anything in Thing.lookupAll():
                    anything.x = anything.x + 1

            messages = self.cells.renderMessages()

            self.assertTrue(
                len(self.cells) < 20,
                "Have %s cells at pass %s" % (len(self.cells), i))
            self.assertTrue(
                len(messages) < 20,
                "Got %s messages at pass %s" % (len(messages), i))
Esempio n. 2
0
    def test_cells_memory_leak1(self):
        cell = Subscribed(lambda: Sequence([
            Span("Thing(k=%s).x = %s" % (thing.k, thing.x))
            for thing in Thing.lookupAll(k=0)
        ]))

        def workFn(db, cells, iterations=5000):
            with db.view():
                thing = Thing.lookupAny(k=0)

            for counter in range(iterations):
                with db.transaction():
                    thing.delete()
                    thing = Thing(k=0, x=counter)

                cells.renderMessages()

        def initFn(db, cells):
            with db.transaction():
                Thing(k=0, x=0)

            cells.renderMessages()

            workFn(db, cells, iterations=500)

        self.helper_memory_leak(cell, initFn, workFn, 1)
Esempio n. 3
0
def servicesTableDataPrep(s, field, serviceCounts):
    """Prep data for display in services table.

    s : service object
        service data dictionary
    field : str
    serviceCounts : list of ints
    """

    if field == 'Service':
        data = Clickable(s.name, "/services/" + s.name)
    elif field == 'Codebase Status':
        data = (
            Clickable(
                Sequence([Octicon('stop').color('red'),
                          Span('Unlocked')]), lambda: s.lock())
            if s.isUnlocked else Clickable(
                Sequence([Octicon('shield').color('green'),
                          Span('Locked')]), lambda: s.prepare())
            if s.isLocked else Clickable(
                Sequence([Octicon('shield').color('orange'),
                          Span('Prepared')]), lambda: s.unlock()))
    elif field == 'Codebase':
        data = (str(s.codebase) if s.codebase else "")
    elif field == 'Module':
        data = s.service_module_name
    elif field == 'Class':
        data = s.service_class_name
    elif field == 'Placement':
        data = s.placement
    elif field == 'Active':
        data = Subscribed(
            lambda: len(service_schema.ServiceInstance.lookupAll(service=s)))
    elif field == 'TargetCount':
        data = Dropdown(s.target_count, [(str(ct), __serviceCountSetter(s, ct))
                                         for ct in serviceCounts])
    elif field == 'Cores':
        data = str(s.coresUsed)
    elif field == 'RAM':
        data = str(s.gbRamUsed)
    elif field == 'Boot Status':
        data = (Popover(Octicon("alert"), "Failed",
                        Traceback(s.lastFailureReason or "<Unknown>"))
                if s.isThrottled() else "")
    else:
        data = ""
    return data
Esempio n. 4
0
def view():
    buttons = Sequence([
        Padding(),
        Button(Sequence([Octicon('shield').color('green'),
                         Span('Lock ALL')]),
               lambda: [s.lock() for s in service_schema.Service.lookupAll()]),
        Button(
            Sequence([Octicon('shield').color('orange'),
                      Span('Prepare ALL')]),
            lambda: [s.prepare() for s in service_schema.Service.lookupAll()]),
        Button(
            Sequence([Octicon('stop').color('red'),
                      Span('Unlock ALL')]),
            lambda: [s.unlock() for s in service_schema.Service.lookupAll()]),
    ])
    tabs = Tabs(Services=servicesTable(), Hosts=hostsTable())
    return Sequence([buttons, tabs])
Esempio n. 5
0
 def test_subscribed_sequence_html_valid(self):
     cell = SubscribedSequence(
         lambda: Thing.lookupAll(k=0),
         lambda thing: Span("X: %s, K: %s" % (thing.x, thing.k)))
     cell.cells = self.cells
     cell.recalculate()
     html = cell.contents
     self.assertHTMLNotEmpty(html)
     self.assertHTMLValid(html)
Esempio n. 6
0
        def checkThing2s():
            ensureSubscribedType(Thing2)

            res = Sequence([
                Span("Thing(k=%s).x = %s" % (thing.k, thing.x))
                for thing in Thing2.lookupAll()
            ])

            computed.set()

            return res
Esempio n. 7
0
    def test_cells_memory_leak2(self):
        cell = (
            SubscribedSequence(
                lambda: Thing.lookupAll(k=0),
                lambda thing: Subscribed(lambda: Span("Thing(k=%s).x = %s" %
                                                      (thing.k, thing.x)))) +
            SubscribedSequence(
                lambda: Thing.lookupAll(k=1),
                lambda thing: Subscribed(lambda: Span("Thing(k=%s).x = %s" %
                                                      (thing.k, thing.x)))))

        def workFn(db, cells, iterations=5000):
            with db.view():
                thing = Thing.lookupAny(k=0)
                self.assertTrue(thing)
                self.assertTrue(Thing.lookupAny())

            for counter in range(iterations):
                with db.transaction():
                    if counter % 3 == 0:
                        thing.k = 1 - thing.k
                        thing.delete()
                        thing = Thing(x=counter, k=0)

                    self.assertTrue(Thing.lookupAny())
                    all_things = Thing.lookupAll()
                    self.assertEqual(len(all_things), 1)
                    for anything in all_things:
                        anything.x = anything.x + 1

                cells.renderMessages()

        def initFn(db, cells):
            with db.transaction():
                Thing(x=1, k=0)

            cells.renderMessages()

            workFn(db, cells, iterations=500)

        self.helper_memory_leak(cell, initFn, workFn, 1)
Esempio n. 8
0
def mainBar(display, toggles, current_username, authorized_groups_text):
    """Main header bar.

    Parameters:
    -----------
    display: serviceDisplay object
    togges: list of servicesToggles
    current_username : text
    authorized_groups_text: text
    """

    return (HeaderBar([
        Subscribed(
            lambda: Dropdown("Service", [("All", "/services")] + [
                (s.name, "/services/" + s.name)
                for s in sorted(service_schema.Service.lookupAll(),
                                key=lambda s: s.name)
            ]), )
    ], toggles, [
        LargePendingDownloadDisplay(),
        Octicon('person') + Span(current_username),
        Span('Authorized Groups: {}'.format(authorized_groups_text)),
        Button(Octicon('sign-out'), '/logout')
    ]) + Main(display))
Esempio n. 9
0
    def test_cells_subscriptions(self):
        self.cells.withRoot(
            Subscribed(lambda: Sequence([
                Span("Thing(k=%s).x = %s" % (thing.k, thing.x))
                for thing in Thing.lookupAll()
            ])))

        self.cells.renderMessages()

        with self.db.transaction():
            Thing(x=1, k=1)
            Thing(x=2, k=2)

        self.cells._recalculateCells()

        with self.db.transaction():
            Thing(x=3, k=3)

        # three 'Span', three 'Text', the Sequence, the Subscribed, and a delete
        self.assertEqual(len(self.cells.renderMessages()), 9)
Esempio n. 10
0
 def test_span_html_valid(self):
     cell = Span("Some spanned text")
     cell.recalculate()
     html = cell.contents
     self.assertHTMLNotEmpty(html)
     self.assertHTMLValid(html)